@@ -34,7 +34,10 @@ public struct ProcessResult: CustomStringConvertible {
34
34
public enum ExitStatus : Equatable {
35
35
/// The process was terminated normally with a exit code.
36
36
case terminated( code: Int32 )
37
- #if !os(Windows)
37
+ #if os(Windows)
38
+ /// The process was terminated abnormally.
39
+ case abnormal( exception: UInt32 )
40
+ #else
38
41
/// The process was terminated due to a signal.
39
42
case signalled( signal: Int32 )
40
43
#endif
@@ -64,12 +67,17 @@ public struct ProcessResult: CustomStringConvertible {
64
67
arguments: [ String ] ,
65
68
environment: [ String : String ] ,
66
69
exitStatusCode: Int32 ,
70
+ normal: Bool ,
67
71
output: Result < [ UInt8 ] , Swift . Error > ,
68
72
stderrOutput: Result < [ UInt8 ] , Swift . Error >
69
73
) {
70
74
let exitStatus : ExitStatus
71
75
#if os(Windows)
72
- exitStatus = . terminated( code: exitStatusCode)
76
+ if normal {
77
+ exitStatus = . terminated( code: exitStatusCode)
78
+ } else {
79
+ exitStatus = . abnormal( exception: UInt32 ( exitStatusCode) )
80
+ }
73
81
#else
74
82
if WIFSIGNALED ( exitStatusCode) {
75
83
exitStatus = . signalled( signal: WTERMSIG ( exitStatusCode) )
@@ -726,6 +734,7 @@ public final class Process {
726
734
let p = _process!
727
735
p. waitUntilExit ( )
728
736
let exitStatusCode = p. terminationStatus
737
+ let normalExit = p. terminationReason == . exit
729
738
#else
730
739
var exitStatusCode : Int32 = 0
731
740
var result = waitpid ( processID, & exitStatusCode, 0 )
@@ -735,13 +744,15 @@ public final class Process {
735
744
if result == - 1 {
736
745
self . state = . failed( SystemError . waitpid ( errno) )
737
746
}
747
+ let normalExit = !WIFSIGNALED( result)
738
748
#endif
739
749
740
750
// Construct the result.
741
751
let executionResult = ProcessResult (
742
752
arguments: arguments,
743
753
environment: environment,
744
754
exitStatusCode: exitStatusCode,
755
+ normal: normalExit,
745
756
output: stdoutResult,
746
757
stderrOutput: stderrResult
747
758
)
@@ -970,7 +981,10 @@ extension ProcessResult.Error: CustomStringConvertible {
970
981
switch result. exitStatus {
971
982
case . terminated( let code) :
972
983
stream <<< " terminated( \( code) ): "
973
- #if !os(Windows)
984
+ #if os(Windows)
985
+ case . abnormal( let exception) :
986
+ stream <<< " abnormal( \( exception) ): "
987
+ #else
974
988
case . signalled( let signal) :
975
989
stream <<< " signalled( \( signal) ): "
976
990
#endif
0 commit comments