mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 05:49:23 +02:00
+ TProcess.WaitForExit implementation with timeout
git-svn-id: trunk@32991 -
This commit is contained in:
parent
d2a7f17d8c
commit
bdbdee6acf
@ -143,6 +143,11 @@ begin
|
|||||||
Result:=True;
|
Result:=True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Function TProcess.WaitOnExit(Timeout : DWord) : Boolean;
|
||||||
|
begin
|
||||||
|
Result:=True;
|
||||||
|
end;
|
||||||
|
|
||||||
Function TProcess.Suspend : Longint;
|
Function TProcess.Suspend : Longint;
|
||||||
begin
|
begin
|
||||||
Result:=0;
|
Result:=0;
|
||||||
|
@ -126,6 +126,11 @@ begin
|
|||||||
Result:=True;
|
Result:=True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Function TProcess.WaitOnExit(Timeout : DWord) : Boolean;
|
||||||
|
begin
|
||||||
|
Result:=True;
|
||||||
|
end;
|
||||||
|
|
||||||
Function TProcess.Suspend : Longint;
|
Function TProcess.Suspend : Longint;
|
||||||
begin
|
begin
|
||||||
Result:=0;
|
Result:=0;
|
||||||
|
@ -121,6 +121,7 @@ Type
|
|||||||
Function Suspend : Integer; virtual;
|
Function Suspend : Integer; virtual;
|
||||||
Function Terminate (AExitCode : Integer): Boolean; virtual;
|
Function Terminate (AExitCode : Integer): Boolean; virtual;
|
||||||
Function WaitOnExit : Boolean;
|
Function WaitOnExit : Boolean;
|
||||||
|
Function WaitOnExit(Timeout : DWord) : Boolean;
|
||||||
Property WindowRect : Trect Read GetWindowRect Write SetWindowRect;
|
Property WindowRect : Trect Read GetWindowRect Write SetWindowRect;
|
||||||
Property Handle : THandle Read FProcessHandle;
|
Property Handle : THandle Read FProcessHandle;
|
||||||
Property ProcessHandle : THandle Read FProcessHandle;
|
Property ProcessHandle : THandle Read FProcessHandle;
|
||||||
|
@ -459,6 +459,27 @@ begin
|
|||||||
FRunning:=False;
|
FRunning:=False;
|
||||||
end;
|
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;
|
Function TProcess.Suspend : Longint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -36,10 +36,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
Function TProcess.PeekExitStatus : Boolean;
|
Function TProcess.PeekExitStatus : Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
GetExitCodeProcess(ProcessHandle,FExitCode);
|
Result:=GetExitCodeProcess(ProcessHandle,FExitCode) and (FExitCode<>Still_Active);
|
||||||
Result:=(FExitCode<>Still_Active);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function GetStartupFlags (P : TProcess): Cardinal;
|
Function GetStartupFlags (P : TProcess): Cardinal;
|
||||||
@ -137,6 +135,7 @@ begin
|
|||||||
FillChar(SI,SizeOf(SI),0);
|
FillChar(SI,SizeOf(SI),0);
|
||||||
With SI do
|
With SI do
|
||||||
begin
|
begin
|
||||||
|
cb:=SizeOf(SI);
|
||||||
dwFlags:=GetStartupFlags(P);
|
dwFlags:=GetStartupFlags(P);
|
||||||
if P.FShowWindow<>swoNone then
|
if P.FShowWindow<>swoNone then
|
||||||
dwFlags:=dwFlags or Startf_UseShowWindow
|
dwFlags:=dwFlags or Startf_UseShowWindow
|
||||||
@ -307,10 +306,8 @@ Var
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
Function TProcess.WaitOnExit : Boolean;
|
Function TProcess.WaitOnExit : Boolean;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
R : DWord;
|
R : DWord;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
R:=WaitForSingleObject (FProcessHandle,Infinite);
|
R:=WaitForSingleObject (FProcessHandle,Infinite);
|
||||||
Result:=(R<>Wait_Failed);
|
Result:=(R<>Wait_Failed);
|
||||||
@ -319,6 +316,19 @@ begin
|
|||||||
FRunning:=False;
|
FRunning:=False;
|
||||||
end;
|
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;
|
Function TProcess.Suspend : Longint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -243,10 +243,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
Function TProcess.WaitOnExit : Boolean;
|
Function TProcess.WaitOnExit : Boolean;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
R : DWord;
|
R : DWord;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
R:=WaitForSingleObject (FProcessHandle,Infinite);
|
R:=WaitForSingleObject (FProcessHandle,Infinite);
|
||||||
Result:=(R<>Wait_Failed);
|
Result:=(R<>Wait_Failed);
|
||||||
@ -255,6 +253,21 @@ begin
|
|||||||
FRunning:=False;
|
FRunning:=False;
|
||||||
end;
|
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;
|
Function TProcess.Suspend : Longint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user