Autor Beitrag
~~MAINFRAIME²~~
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

WinXP 32/64bit
Delphi 2005
BeitragVerfasst: Do 19.07.07 09:35 
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.
ausblenden Delphi-Quelltext
1:
WaitForAppDone('T:\tmp\yxz (142) (x) (-)\ooo\do.bat');					

So bekomme ich false zurück und GetLastError ist 0.

ausblenden volle Höhe Delphi-Quelltext
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
  // Initialize the structures
  FillChar(proc_info, sizeof(TProcessInformation), 0);
  FillChar(startinfo, sizeof(TStartupInfo), 0);
  startinfo.cb := sizeof(TStartupInfo);

  // Attempts to create the process
  if CreateProcess(
  PChar(process),
  nil,
  nil,
  nil,
  false,
  IDLE_PRIORITY_CLASS,
  nil,
  PChar(ExtractFilePath(process)),
  startinfo,
  proc_info
  ) <> False then begin
    // The process has been successfully created
    // Now let's wait till it ends...
    WaitForSingleObject(proc_info.hProcess, INFINITE);
    // Process has finished. Now we should close it.
    GetExitCodeProcess(proc_info.hProcess, ExitCode);  // Optional
    CloseHandle(proc_info.hThread);
    CloseHandle(proc_info.hProcess);
    result:= true;
  end else begin
    // Failure creating the process
    result:= false;
  end;//if
end;


Und wenn ich es so mache geht es auch nicht.
ausblenden 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.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 21.07.07 01:36 
ausblenden Quelltext
1:
2:
3:
C:\Dokumente und Einstellungen\Michael>net helpmsg 126

Das angegebene Modul wurde nicht gefunden.

Klingt so, als wenn der Pfad nicht stimmt.