ExecAndWait

How to execute a command and then wait for it to finish.

procedure ExecAndWait(CommandLine: string; CommandShow: Longint);

var

  pi: TProcessInformation;

  si: TStartupInfo;

begin

  FillChar(si, sizeof(si), #0);

  si.cb := sizeof(si);

  si.dwFlags := STARTF_USESHOWWINDOW;

  si.wShowWindow := CommandShow;

  CreateProcess(nil, PChar(CommandLine), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, si, pi);

  WaitForSingleObject(pi.hProcess, INFINITE);

  CloseHandle(pi.hProcess);

  CloseHandle(pi.hThread);

end;

 

Share this article!

Follow us!

Find more helpful articles: