Instance Property

terminationStatus

Returns the exit status returned by the receiver’s executable.

Declaration

var terminationStatus: Int32 { get }

Return Value

The exit status returned by the receiver’s executable.

Discussion

Each task defines and documents how its return value should be interpreted. For example, many commands return 0 if they complete successfully or an error code if they don’t. You’ll need to look at the documentation for that task to learn what values it returns under what circumstances.

This method raises an NSInvalidArgumentException if the receiver is still running. Verify that the receiver is not running before you use it.

let task: NSTask = // Create and initialize a task
if !task.isRunning {
    let status = task.terminationStatus
    if status == 0 {
        print("Task succeeded.")
    } else {
        print("Task failed.")
    }
}

See Also

Querying the Task State

var isRunning: Bool

Returns whether the receiver is still running.

var terminationReason: Process.TerminationReason

Returns the reason the task was terminated.