ソースを参照

* Added ExitCode (different from ExitStatus)

git-svn-id: trunk@26706 -
michael 11 年 前
コミット
8a4e0e6e84

+ 9 - 0
packages/fcl-process/src/process.pp

@@ -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;
 

+ 6 - 0
packages/fcl-process/src/process.txt

@@ -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.

+ 12 - 7
packages/fcl-process/src/unix/process.inc

@@ -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;