![]() |
Problem mit WaitForSingleObject
Ich hab da ein kleines Problem :
Wenn ich die untenstehende Procedure (Hab ich hier aus dem Forum) aufrufe bleibt er in :
Delphi-Quellcode:
dieser Schleife hängen.
repeat
WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,30); Application.ProcessMessages; until (WaitHandle <> WAIT_TIMEOUT) or application.terminated; In test.php setht nur ein simples
Code:
Wenn ich nur einen PHP-Syntaxcheck mache (mit dieser Prozedur) funtioniert alles, aber mit dem Ausführen des Ganzen harperts irgendwie.
<?phpinfo();?>
Der Path existiert und die test.php findet er auch (wenn ich den PHP.EXE Prozess kille sehe ich einen Anfang der PHPINFO() ) Ahja, der Aufruf auf der Kommandozeile dauert ca. 0,5 Sec. (im Fenster geteset). Hat da jemand ne Idee ? Aufruf :
Delphi-Quellcode:
Procedure :
phpexe := 'c:\php.php.exe';
pathname := 'd:\Apache Group\Apache\htdocs\test.php'; tmp := TStringList.Create; x := phpexe + ' -f "' + pathname + '"'; CaptureDosCmd(x,tmp); [...]
Delphi-Quellcode:
procedure TEditForm.CaptureDosCmd(command:String; var OutputMemo:TStringList);
const CaptureBufferSize = 64000; var SecAttrib : TSecurityAttributes; ReadPipe,writePipe : THandle; Startup : TStartUpInfo; ProcessInfo : TProcessInformation; CaptureBuffer : Pchar; BytesRead : DWord; WaitHandle : DWord; begin OutPutMemo.clear; // OutputMemo.add('# Starte "'+command+'"'); With SecAttrib do begin nlength := SizeOf(TSecurityAttributes); binherithandle := true; lpsecuritydescriptor := nil; end; if Createpipe (ReadPipe, writePipe, @SecAttrib, 0) then begin CaptureBuffer := AllocMem(CaptureBufferSize + 1); FillChar(Startup,Sizeof(Startup),#0); Startup.cb := SizeOf(Startup); Startup.hStdOutput := writePipe; Startup.hStdInput := ReadPipe; Startup.dwFlags := STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW; // Startup.wShowWindow := SW_HIDE; Startup.wShowWindow := SW_NORMAL; if CreateProcess(nil, PChar(command), @SecAttrib, @SecAttrib, true, NORMAL_PRIORITY_CLASS, nil, nil, Startup, ProcessInfo) then begin repeat WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,30); Application.ProcessMessages; until (WaitHandle <> WAIT_TIMEOUT) or application.terminated; if not application.terminated then begin Repeat BytesRead := 0; ReadFile(ReadPipe,CaptureBuffer[0],CaptureBufferSize,BytesRead,nil); CaptureBuffer[BytesRead]:= #0; OemToAnsi(CaptureBuffer,CaptureBuffer); OutputMemo.Text := OutputMemo.Text+String(CaptureBuffer); until (BytesRead < CaptureBufferSize); end else OutPutMemo.add('# Operation canceled!'); FreeMem(CaptureBuffer); CloseHandle(ProcessInfo.hProcess); CloseHandle(ProcessInfo.hThread); CloseHandle(ReadPipe); CloseHandle(writePipe); end else OutPutMemo.add('# cannot create process. Error: #'+inttostr(getlasterror)); end else OutPutMemo.add('# cannot create pipe. Error: #'+inttostr(getlasterror)); end; |
Re: Problem mit WaitForSingleObject
Zitat:
If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError.
Delphi-Quellcode:
Du solltest auch Resourceschutzblöcke für deine Handles verwenden.
repeat
WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,30); if WaitHandle=WAIT_FAILED then // <--------- RaiseLastWin32Error; Application.ProcessMessages; until (WaitHandle <> WAIT_TIMEOUT) or application.terminated; |
Re: Problem mit WaitForSingleObject
Zitat:
Nee, Der Process, der erschaffen wird, hängt sich weg. (Denke ich) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:05 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz