Ich möchte aus meinem Programm ein externes aufrufen und warten bis es fertig ist,
dass funktioniert nur nicht immer.
Wenn es funktioniert bekomme ich bei GetLastError 126 aber wenn ich zum Beispiel klammern im Pfad habe geht es nicht und ich bekomme bei GetLastError 0.
z.B.
Delphi-Quelltext
1:
| WaitForAppDone('T:\tmp\yxz (142) (x) (-)\ooo\do.bat'); |
So bekomme ich false zurück und GetLastError ist 0.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
| function WaitForAppDone(process: string): boolean; var proc_info: TProcessInformation; startinfo: TStartupInfo; ExitCode: longword; begin FillChar(proc_info, sizeof(TProcessInformation), 0); FillChar(startinfo, sizeof(TStartupInfo), 0); startinfo.cb := sizeof(TStartupInfo);
if CreateProcess( PChar(process), nil, nil, nil, false, IDLE_PRIORITY_CLASS, nil, PChar(ExtractFilePath(process)), startinfo, proc_info ) <> False then begin WaitForSingleObject(proc_info.hProcess, INFINITE); GetExitCodeProcess(proc_info.hProcess, ExitCode); CloseHandle(proc_info.hThread); CloseHandle(proc_info.hProcess); result:= true; end else begin result:= false; end;end; |
Und wenn ich es so mache geht es auch nicht.
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| if CreateProcess( PChar('"' + process + '"'), nil, nil, nil, false, IDLE_PRIORITY_CLASS, nil, PChar('"' + ExtractFilePath(process) + '"'), startinfo, proc_info ) |
Also ich muss ein externes Programm oder eine Batchdatei aufrufen und darauf warten bis es fertig ist und natürlich muss das Arbeitsverzeichnis dem des Programms entsprechen.