* Added ExitCode (different from ExitStatus)

git-svn-id: trunk@26706 -
This commit is contained in:
michael 2014-02-07 13:03:17 +00:00
parent 73c26bd6be
commit 8a4e0e6e84
3 changed files with 27 additions and 7 deletions

View File

@ -81,6 +81,7 @@ Type
FPipeBufferSize : cardinal;
Procedure FreeStreams;
Function GetExitStatus : Integer;
Function GetExitCode : Integer;
Function GetRunning : Boolean;
Function GetWindowRect : TRect;
procedure SetCommandLine(const AValue: String);
@ -130,6 +131,7 @@ Type
Property Output : TInputPipeStream Read FOutputStream;
Property Stderr : TinputPipeStream Read FStderrStream;
Property ExitStatus : Integer Read GetExitStatus;
Property ExitCode : Integer Read GetExitCode;
Property InheritHandles : Boolean Read FInheritHandles Write FInheritHandles;
{$ifdef UNIX}
property OnForkEvent : TProcessForkEvent Read FForkEvent Write FForkEvent;
@ -280,6 +282,13 @@ begin
Result:=FExitCode;
end;
{$IFNDEF OS_HASEXITCODE}
Function TProcess.GetExitCode : Integer;
begin
Result:=GetExitStatus;
end;
{$ENDIF}
Function TProcess.GetRunning : Boolean;

View File

@ -160,6 +160,12 @@ Property ExitStatus : Integer;
Read-Only
This returns the exit status of the application, or STILL_ACTIVE
(defined in Windows.pas) if the application is still running.
This is the low-level exit status as reported by the OS.
Property ExitCode : Integer;
Read-Only
This returns the exit code as returned by the application, if it exited correcly.
It returns 0 if the process didn't exit correctly (e.g. a signal).
Property FillAttribute : Integer;
For console processes only.

View File

@ -10,6 +10,8 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{$DEFINE OS_HASEXITCODE}
uses
ctypes,
UnixType,
@ -37,6 +39,15 @@ begin
// Do nothing. Win32 call.
end;
Function TProcess.GetExitCode : Integer;
begin
if wifexited(FExitCode) then
Result:=wexitstatus(FExitCode)
else
Result:=0;
end;
Function TProcess.PeekExitStatus : Boolean;
var
res: cint;
@ -45,13 +56,7 @@ begin
res:=fpWaitPid(Handle,pcint(@FExitCode),WNOHANG);
until (res<>-1) or (fpgeterrno<>ESysEINTR);
result:=res=Handle;
If Result then
begin
if wifexited(FExitCode) then
FExitCode:=wexitstatus(FExitCode);
// else pass errorvalue unmodified like shell does, bug #22055
end
else
If Not Result then
FexitCode:=cardinal(-1); // was 0, better testable for abnormal exit.
end;