Running external programs...

Miscellaneous Forums/General Discussion/Running external programs...

You can definitely call a process and only return program flow to your app when the process has ended. I think you have to pass Inifinite as one of the params, hang on ... Here's something I made in Delphi years ago

Function ccRunFile(Command: String; State: TRunState; TimeLimit: Integer): Integer;
var
  zAppName:array[0..512] of char;
  zCurDir:array[0..255] of char;
  WorkDir:String;
  StartupInfo:TStartupInfo;
  ProcessInfo:TProcessInformation;
begin
  StrPCopy(zAppName, Command);
  GetDir(0,WorkDir);
  StrPCopy(zCurDir,WorkDir);
	FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);

  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Ord(State);
  if not CreateProcess(nil,
    zAppName,                      { pointer to command line string }
    nil,                           { pointer to process security attributes }
    nil,                           { pointer to thread security attributes }
    false,                         { handle inheritance flag }
    CREATE_NEW_CONSOLE or          { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil,                           { pointer to new environment block }
    nil,                           { pointer to current directory name }
    StartupInfo,                   { pointer to STARTUPINFO }
    ProcessInfo) then Result := STILL_ACTIVE { pointer to PROCESS_INF }

	else
  begin
    If TimeLimit <> INFINITE Then
      TimeLimit := TimeLimit * 1000;

    WaitforSingleObject(ProcessInfo.hProcess, TimeLimit);
    GetExitCodeProcess(ProcessInfo.hProcess,Result);
  end;

  If Result = STILL_ACTIVE Then
  Begin
    If TimeOutMsg = '#NONE#' Then
      TimeOutMsg := 'Application time out on: ' + #13 + #13 + Command;

    TerminateProcess(ProcessInfo.hProcess,256);
    If TimeOutMsg <> '' Then
      ArcMessage(TimeOutMsg, amError);

    TimeOutMsg := '#NONE#';
  End;
end;