Happy Day.

Here's a function I once posted on the list which I think will help you out.

Cheers.
                            BJ...

procedure ExecuteAndWait (executable: string);
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  CreatedOK: boolean;
  status: integer;
  ev: TEvent;
  i: integer;
begin
  ev := TEvent.Create(nil, False, False, 'TimeKiller');
  try
    FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
    with StartupInfo do
    begin
      cb := SizeOf(TStartupInfo);
      dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
      wShowWindow := SW_HIDE;
    end;

    CreatedOk := CreateProcess(nil, PChar(executable),
                               nil, nil, False, NORMAL_PRIORITY_CLASS, nil,
nil,
                               StartupInfo, ProcessInfo);
    if CreatedOK then
    begin
      { Wait around for the process to end. }
      with ProcessInfo do
      begin
        WaitForInputIdle(hProcess, INFINITE);
        GetExitCodeProcess(hProcess, status);
        while status = STILL_ACTIVE do
        begin
          GetExitCodeProcess(hProcess, status);
          { A quarter second delay here so this process doesn't hog CPU }
          ev.WaitFor(250);
          Application.ProcessMessages;
        end;
        CloseHandle(hThread);
        CloseHandle(hProcess);
      end; { with ProcessInfo }
    end; {if CreatedOK }
  finally
    ev.Free;
  end;
end;

-----Original Message-----
From: Phil Scadden <[EMAIL PROTECTED]>
To: Multiple recipients of list DELphi <[EMAIL PROTECTED]>
Date: Wednesday, 22 March 2000 11:32
Subject: [DUG]: shelling programs in sequence...


I want run a program sandwiched between two others.
Ie.
First program runs: it starts another program (a 16 bit one). When the
second
program completes, I want to pretty much guarantee that a 3rd program runs
the moment the finishes - whatever the exit status. Both first and 2nd
programs
have minimal but vital execution to perform. I dont have source for the 2nd
program.

I guess the first program shellexecutes the second, hides itself and waits
for
second program to complete. How does it detect second program done?

Ideas please??

----------------------------------------------------------
Phil Scadden, Institute of Geological and Nuclear Sciences
PO Box 30368, Lower Hutt, New Zealand
Ph +64 4 5704821, fax +64 4 5704603
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to