Board index » delphi » Delphi 2 - Run DOS App, find out when done

Delphi 2 - Run DOS App, find out when done

Quote
Katman wrote:

> I have a very simple problem... I just need to know how to run a DOS
> application and find out when it's finished...

I use CreateProcess() and WaitForSingleObject().  Look at the Online
help for both.

Dana Scott Kaufman
Apogee Information Systems

 

Re:Delphi 2 - Run DOS App, find out when done


I have a very simple problem... I just need to know how to run a DOS
application and find out when it's finished...

here's the actual set-up:

I'm writing an installation program for internet software, for my university..
to bring the number of disks from 5 down to 2 or 3, I need to compress the
files.. using COMPRESS.EXE is not good enough, and I need to use a compressor
such as PKZIP, ARJ, etc... I chose PKZIP.. The program has to run PKUNZIP, and
find out when it's done... if it doesn't, it will prompt the user to put in the
next disk, before its finished extracting... in Delphi 1.0, I could have used
this combination:

  proghandle := winexec('PKUNZIP FILE C:\DIR', SW_MINIMIZED)
  while (getmoduleusage(proghandle)) do;

(or something very similar...  but, getmoduleusage was deleted because of the
32-bit extensions.. the help file says to use the CreateProcess function ...
but I really don't think I have to go through so much trouble just to run a dos
app..

Can someone help?  

thanks in advance

Terry Katz

Re:Delphi 2 - Run DOS App, find out when done


In article <3151E57E.6...@tiac.net>, apo...@tiac.net says...

Quote

>Katman wrote:

>> I have a very simple problem... I just need to know how to run a DOS
>> application and find out when it's finished...

>I use CreateProcess() and WaitForSingleObject().  Look at the Online
>help for both.

>Dana Scott Kaufman
>Apogee Information Systems

If you don't want to use a blocking function (WaitForSingleObject()), grab the
handle from the Process_Information structure, and pass it to
GetExitCodeProcess. If the MsDos window is still open, the status word is
'STILL_ACTIVE'. After the window closes, it is 0. This allows you to simply
poll the value.

--
Tom Wolf
Email (home): tomww...@edp.net
EMail (work): tom.w...@chensys.com
http://www.chensys.com
Representing Insomnia Software and
Employed by Chen Systems

Re:Delphi 2 - Run DOS App, find out when done


On 22 Mar 1996 00:17:35 GMT, kat...@putwest.boces.org (Katman) wrote:

Quote
> I'm writing an installation program for internet software, for my university..
> to bring the number of disks from 5 down to 2 or 3, I need to compress the
> files.. using COMPRESS.EXE is not good enough, and I need to use a compressor
> such as PKZIP, ARJ, etc... I chose PKZIP.. The program has to run PKUNZIP, and
> find out when it's done... if it doesn't, it will prompt the user to put in the
> next disk, before its finished extracting... in Delphi 1.0, I could have used
> this combination:

>   proghandle := winexec('PKUNZIP FILE C:\DIR', SW_MINIMIZED)
>   while (getmoduleusage(proghandle)) do;

> (or something very similar...  but, getmoduleusage was deleted because of the
> 32-bit extensions.. the help file says to use the CreateProcess function ...
> but I really don't think I have to go through so much trouble just to run a dos
> app..

Terry,

Here's a function I've modified to allow both Delphi 1 and 2 to
execute a program and wait until it's finished before returning.

You'll notice it does call CreateProcess.  It's a little "wordy",
but I like it since that function gives far more control over
what's going on.  Besides, you can always write wrappers (like
this one!) to make your life easier...

I hope this helps--

-------------------------------------------------------------------
function WinExecAndWait( Path: Pchar; Visibility: word ): dword;

  var
    InstanceID: THandle;
  {$IFDEF DELPHI16}
    Msg: TMessage;
  {$ELSE}
    Msg: TMsg;
    bStat: BOOL;
    pi: TProcessInformation;
    si: TStartupInfo;
    iExit: DWORD;
    bExit: boolean;
  {$ENDIF}

  begin
  {$IFDEF DELPHI16}
  InstanceID := WinExec( Path, Visibility );
  {$ELSE}
  FillMemory( @si, sizeof( TStartupInfo ), 0 );

  with si do
    begin
    cb := sizeof( TStartupInfo );
    wShowWindow := Visibility;
    end;

  bStat := CreateProcess
    (
    nil,     // address of module name
    Path,    // address of command line
    nil,     // address of process security attributes
    nil,     // address of thread security attributes
    false,   // new process inherits handles
    NORMAL_PRIORITY_CLASS,  // creation flags
    nil,     // address of new environment block
    nil,     // address of current directory name
    si,      // address of STARTUPINFO
    pi       // address of PROCESS_INFORMATION
    );
  {$ENDIF}
  if ( InstanceID < 32 ) then { a value less than 32 indicates an Exec
error }
    Result := InstanceID
  else
    repeat
      while ( PeekMessage( Msg, 0, 0, 0, PM_REMOVE ) ) do
        begin
        if ( Msg.Message = WM_QUIT ) then
          Halt( Msg.wParam );
        TranslateMessage( Msg );
        DispatchMessage( Msg );
        end;
  {$IFDEF DELPHI16}
    until GetModuleUsage( InstanceID ) = 0;
    Result := 0;
  {$ELSE}
      GetExitCodeProcess( pi.hProcess, iExit );
      bExit := iExit <> STILL_ACTIVE;
    until bExit;
    Result := iExit;
  {$ENDIF}
  end;
-------------------------------------------------------------------

Brad Choate <cho...@cswnet.com> | http://www.cswnet.com/~choate
You should have asked that question on the #delphi IRC channel!
Have a Coke and a :)

Other Threads