Board index » delphi » Wait after winexec shells to dos?

Wait after winexec shells to dos?

In article <479bpl$...@tribune.usask.ca>,
   d...@paschools.pa.sk.ca (Graeme Dice) wrote:

Quote
>When I shell to dos using winexec my Delphi program continues
>running.  This causes a file not found error when my program tries to
>read in a file which hasn't been created yet by the dos program.  How
>do I get winexec to wait until the dos program terminates?

>Graeme Dice    d...@paschools.pa.sk.ca

uses Wintypes, WinProcs, Toolhelp, Classes, Forms;

Function WinExecAndWait(Path : string; Visibility : word) : word;
var
  InstanceID : THandle;
  PathLen : integer;
begin
  { inplace conversion of a String to a PChar }
  PathLen := Length(Path);
  Move(Path[1],Path[0],PathLen);
  Path[PathLen] := #0;
  { Try to run the application }
  InstanceID := WinExec(@Path, Visibility);
  if InstanceID < 32 then { a value less than 32 indicates an Exec error }
     Result := InstanceID
  else begin
    Repeat
      Application.ProcessMessages;
    until Application.Terminated or (GetModuleUsage(InstanceID) = 0);
    Result := 32;
  end;
end;

David

--
David Brabant,             | E-mail: David.Brab...@csl.sni.be
Siemens Nixdorf (SNI),     | CIS:    100337,1733
Centre Software de Lige,  | X-400:  C=BE;A=RTT;P=SCN;O=SNI;OU1=LGG1;OU2=S1
2, rue des Fories,         |         S=BRABANT;G=DAVID
4020 Lige (BELGIUM)       | HTTP:   www.sni.de       www.csl.sni.be/~david

 

Re:Wait after winexec shells to dos?


David.Brab...@csl.sni.be (David Brabant [SNI]) wrote:

Quote
}>read in a file which hasn't been created yet by the dos program.  How
}>do I get winexec to wait until the dos program terminates?
}>
}uses Wintypes, WinProcs, Toolhelp, Classes, Forms;
}
}Function WinExecAndWait(Path : string; Visibility : word) : word;
}var
}  InstanceID : THandle;
}  PathLen : integer;
}begin
}  { inplace conversion of a String to a PChar }
}  PathLen := Length(Path);
}  Move(Path[1],Path[0],PathLen);
}  Path[PathLen] := #0;
}  { Try to run the application }
}  InstanceID := WinExec(@Path, Visibility);
}  if InstanceID < 32 then { a value less than 32 indicates an Exec error }
}     Result := InstanceID
}  else begin
}    Repeat
}      Application.ProcessMessages;
}    until Application.Terminated or (GetModuleUsage(InstanceID) = 0);
}    Result := 32;
}  end;
}end;

Someone owns a copy of "Delphi Developer's Guide"!  :-)

I was going to post this, but I didn't know what Steve or Xavier would think
about having code copied from their book.  What about it Steve?
----------------------------------------------------------------------
Kerry Sanders                     | "Cause when ya stop dreaming
E-Mail: ksand...@mindspring.com   |       its time to die" - CHANGE
----------------------------------------------------------------------

Other Threads