mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-24 05:59:34 +02:00
+ TProcess.WaitForExit implementation with timeout
git-svn-id: trunk@32991 -
This commit is contained in:
parent
d2a7f17d8c
commit
bdbdee6acf
packages/fcl-process/src
@ -143,6 +143,11 @@ begin
|
||||
Result:=True;
|
||||
end;
|
||||
|
||||
Function TProcess.WaitOnExit(Timeout : DWord) : Boolean;
|
||||
begin
|
||||
Result:=True;
|
||||
end;
|
||||
|
||||
Function TProcess.Suspend : Longint;
|
||||
begin
|
||||
Result:=0;
|
||||
|
@ -126,6 +126,11 @@ begin
|
||||
Result:=True;
|
||||
end;
|
||||
|
||||
Function TProcess.WaitOnExit(Timeout : DWord) : Boolean;
|
||||
begin
|
||||
Result:=True;
|
||||
end;
|
||||
|
||||
Function TProcess.Suspend : Longint;
|
||||
begin
|
||||
Result:=0;
|
||||
|
@ -121,6 +121,7 @@ Type
|
||||
Function Suspend : Integer; virtual;
|
||||
Function Terminate (AExitCode : Integer): Boolean; virtual;
|
||||
Function WaitOnExit : Boolean;
|
||||
Function WaitOnExit(Timeout : DWord) : Boolean;
|
||||
Property WindowRect : Trect Read GetWindowRect Write SetWindowRect;
|
||||
Property Handle : THandle Read FProcessHandle;
|
||||
Property ProcessHandle : THandle Read FProcessHandle;
|
||||
|
@ -459,6 +459,27 @@ begin
|
||||
FRunning:=False;
|
||||
end;
|
||||
|
||||
Function TProcess.WaitOnExit(Timeout : DWord) : Boolean;
|
||||
var
|
||||
res: cint;
|
||||
begin
|
||||
Result:=false;
|
||||
res:=fpWaitPid(Handle,pcint(@FExitCode),WNOHANG);
|
||||
while (res=-1) and (fpgeterrno=ESysEINTR) do
|
||||
begin
|
||||
if Timeout=0 then
|
||||
Exit;
|
||||
Sleep(1);
|
||||
dec(Timeout);
|
||||
res:=fpWaitPid(Handle,pcint(@FExitCode),WNOHANG);
|
||||
end;
|
||||
result:=res=Handle;
|
||||
If Not Result then
|
||||
FexitCode:=cardinal(-1) // was 0, better testable for abnormal exit.
|
||||
else
|
||||
FRunning:=False;
|
||||
end;
|
||||
|
||||
Function TProcess.Suspend : Longint;
|
||||
|
||||
begin
|
||||
|
@ -36,10 +36,8 @@ begin
|
||||
end;
|
||||
|
||||
Function TProcess.PeekExitStatus : Boolean;
|
||||
|
||||
begin
|
||||
GetExitCodeProcess(ProcessHandle,FExitCode);
|
||||
Result:=(FExitCode<>Still_Active);
|
||||
Result:=GetExitCodeProcess(ProcessHandle,FExitCode) and (FExitCode<>Still_Active);
|
||||
end;
|
||||
|
||||
Function GetStartupFlags (P : TProcess): Cardinal;
|
||||
@ -137,6 +135,7 @@ begin
|
||||
FillChar(SI,SizeOf(SI),0);
|
||||
With SI do
|
||||
begin
|
||||
cb:=SizeOf(SI);
|
||||
dwFlags:=GetStartupFlags(P);
|
||||
if P.FShowWindow<>swoNone then
|
||||
dwFlags:=dwFlags or Startf_UseShowWindow
|
||||
@ -307,10 +306,8 @@ Var
|
||||
end;
|
||||
|
||||
Function TProcess.WaitOnExit : Boolean;
|
||||
|
||||
Var
|
||||
R : DWord;
|
||||
|
||||
begin
|
||||
R:=WaitForSingleObject (FProcessHandle,Infinite);
|
||||
Result:=(R<>Wait_Failed);
|
||||
@ -319,6 +316,19 @@ begin
|
||||
FRunning:=False;
|
||||
end;
|
||||
|
||||
Function TProcess.WaitOnExit(Timeout : DWord) : Boolean;
|
||||
Var
|
||||
R : DWord;
|
||||
begin
|
||||
R:=WaitForSingleObject (FProcessHandle,Timeout);
|
||||
Result:=R=0;
|
||||
If Result then
|
||||
begin
|
||||
GetExitStatus;
|
||||
FRunning:=False;
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TProcess.Suspend : Longint;
|
||||
|
||||
begin
|
||||
|
@ -243,10 +243,8 @@ begin
|
||||
end;
|
||||
|
||||
Function TProcess.WaitOnExit : Boolean;
|
||||
|
||||
Var
|
||||
R : DWord;
|
||||
|
||||
begin
|
||||
R:=WaitForSingleObject (FProcessHandle,Infinite);
|
||||
Result:=(R<>Wait_Failed);
|
||||
@ -255,6 +253,21 @@ begin
|
||||
FRunning:=False;
|
||||
end;
|
||||
|
||||
|
||||
Function TProcess.WaitOnExit(Timeout : DWord) : Boolean;
|
||||
Var
|
||||
R : DWord;
|
||||
begin
|
||||
R:=WaitForSingleObject (FProcessHandle,Timeout);
|
||||
Result:=R=0;
|
||||
If Result then
|
||||
begin
|
||||
GetExitStatus;
|
||||
FRunning:=False;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Function TProcess.Suspend : Longint;
|
||||
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user