Process.Execute // capture all proc output (if required) - watch for proc ending quickly, but data still waiting while ( Process.Running ) // cycle whilst process active OR ( (poUsePipes IN Process.Options) AND (Process.Output.NumBytesAvailable > 0) ) // OR finished already, still data waiting do begin Sleep(1); if Terminated then break; // no pipes - not past here as causes exceptions to read process pipes if not enabled if NOT (poUsePipes IN Process.Options) then continue; // read output BytesAvailable := Process.Output.NumBytesAvailable; if BytesAvailable > 0 then begin SetLength(str1, BytesAvailable); Process.OutPut.Read(str1[1], BytesAvailable); StdOutStore += str1; end; // read errors BytesAvailable := Process.Stderr.NumBytesAvailable; if BytesAvailable > 0 then begin SetLength(str1, BytesAvailable); Process.Stderr.Read(str1[1], BytesAvailable); StdErrStore += str1; end; // send input if UsrSendMsg > '' then begin Process.Input.Write(UsrSendMsg[1], Length(UsrSendMsg)); UsrSendMsg := ''; end; end;