AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Problem mit WaitForSingleObject

Ein Thema von Nightshade · begonnen am 19. Jul 2004 · letzter Beitrag vom 20. Jul 2004
Antwort Antwort
Nightshade

Registriert seit: 7. Jan 2003
Ort: Menden
192 Beiträge
 
Delphi 7 Enterprise
 
#1

Problem mit WaitForSingleObject

  Alt 19. Jul 2004, 17:42
Ich hab da ein kleines Problem :

Wenn ich die untenstehende Procedure (Hab ich hier aus dem Forum) aufrufe bleibt er in :

Delphi-Quellcode:
     repeat
        WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,30);
        Application.ProcessMessages;
      until (WaitHandle <> WAIT_TIMEOUT) or application.terminated;
dieser Schleife hängen.

In test.php setht nur ein simples
Code:
<?phpinfo();?>
Wenn ich nur einen PHP-Syntaxcheck mache (mit dieser Prozedur) funtioniert alles, aber mit dem Ausführen des Ganzen harperts irgendwie.

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:
    phpexe := 'c:\php.php.exe';
    pathname := 'd:\Apache Group\Apache\htdocs\test.php';
    tmp := TStringList.Create;
    x := phpexe + ' -f "' + pathname + '"';
    CaptureDosCmd(x,tmp);
    [...]
Procedure :
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;
Christian
Killing for peace is like fucking for virginity

Nightshade
  Mit Zitat antworten Zitat
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#2

Re: Problem mit WaitForSingleObject

  Alt 19. Jul 2004, 18:18
Zitat von Nightshade:
Ich hab da ein kleines Problem :

Wenn ich die untenstehende Procedure (Hab ich hier aus dem Forum) aufrufe bleibt er in :

Delphi-Quellcode:
     repeat
        WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,30);
        Application.ProcessMessages;
      until (WaitHandle <> WAIT_TIMEOUT) or application.terminated;
WaitForSingleObject:
If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError.
Delphi-Quellcode:
repeat
  WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,30);
  if WaitHandle=WAIT_FAILED then // <---------
     RaiseLastWin32Error;
  Application.ProcessMessages;
  until (WaitHandle <> WAIT_TIMEOUT) or application.terminated;
Du solltest auch Resourceschutzblöcke für deine Handles verwenden.
Andreas
  Mit Zitat antworten Zitat
Nightshade

Registriert seit: 7. Jan 2003
Ort: Menden
192 Beiträge
 
Delphi 7 Enterprise
 
#3

Re: Problem mit WaitForSingleObject

  Alt 20. Jul 2004, 13:36
Zitat von shmia:
WaitForSingleObject:
If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError.
Delphi-Quellcode:
repeat
  WaitHandle := WaitForSingleObject( ProcessInfo.hProcess,30);
  if WaitHandle=WAIT_FAILED then // <---------
     RaiseLastWin32Error;
  Application.ProcessMessages;
  until (WaitHandle <> WAIT_TIMEOUT) or application.terminated;
Du solltest auch Resourceschutzblöcke für deine Handles verwenden.
Wenn die Function was anderes als "WAIT_TIMEOUT" zurückliefern würde, würde er nicht in der Schleife hängen bleiben.
Nee, Der Process, der erschaffen wird, hängt sich weg. (Denke ich)
Christian
Killing for peace is like fucking for virginity

Nightshade
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:50 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz