Struct ExitStatus
struct ExitStatus(_)
Describes the result of a process after it has terminated.
This struct is used to represent the exit status or other termination of a child process.
Child processes are created via the Command struct and their exit
status is exposed through the status method, or the wait method
of a Child process.
An ExitStatus represents every possible disposition of a process. On Unix this
is the wait status. It is not simply an exit status (a value passed to exit).
For proper error reporting of failed processes, print the value of ExitStatus or
ExitStatusError using their implementations of Display.
Differences from ExitCode
ExitCode is intended for terminating the currently running process, via
the Termination trait, in contrast to ExitStatus, which represents the
termination of a child process. These APIs are separate due to platform
compatibility differences and their expected usage; it is not generally
possible to exactly reproduce an ExitStatus from a child for the current
process after the fact.
Implementations
impl ExitStatus
fn exit_ok(self: &Self) -> Result<(), ExitStatusError>Was termination successful? Returns a
Result.Examples
# if cfg! // cfg!(unix)fn success(self: &Self) -> boolWas termination successful? Signal termination is not considered a success, and success is defined as a zero exit status.
Examples
use Command; let status = new .arg .status .expect; if status.success elsefn code(self: &Self) -> Option<i32>Returns the exit code of the process, if any.
In Unix terms the return value is the exit status: the value passed to
exit, if the process finished by callingexit. Note that on Unix the exit status is truncated to 8 bits, and that values that didn't come from a program's call toexitmay be invented by the runtime system (often, for example, 255, 254, 127 or 126).On Unix, this will return
Noneif the process was terminated by a signal.ExitStatusExtis an extension trait for extracting any such signal, and other details, from theExitStatus.Examples
use std::process::Command; let status = Command::new("mkdir") .arg("projects") .status() .expect("failed to execute mkdir"); match status.code() { Some(code) => println!("Exited with status code: {code}"), None => println!("Process terminated by signal") }
impl Clone for ExitStatus
fn clone(self: &Self) -> ExitStatus
impl Copy for ExitStatus
impl Debug for ExitStatus
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for ExitStatus
fn default() -> Self
impl Display for ExitStatus
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Eq for ExitStatus
impl ExitStatusExt for process::ExitStatus
fn from_raw(raw: u32) -> Self
impl ExitStatusExt for process::ExitStatus
fn from_raw(raw: i32) -> Selffn signal(self: &Self) -> Option<i32>fn core_dumped(self: &Self) -> boolfn stopped_signal(self: &Self) -> Option<i32>fn continued(self: &Self) -> boolfn into_raw(self: Self) -> i32
impl Freeze for ExitStatus
impl From for ExitStatus
fn from(error: ExitStatusError) -> Self
impl PartialEq for ExitStatus
fn eq(self: &Self, other: &ExitStatus) -> bool
impl RefUnwindSafe for ExitStatus
impl Send for ExitStatus
impl StructuralPartialEq for ExitStatus
impl Sync for ExitStatus
impl Unpin for ExitStatus
impl UnwindSafe for ExitStatus
impl<T> Any for ExitStatus
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for ExitStatus
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for ExitStatus
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for ExitStatus
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for ExitStatus
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for ExitStatus
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for ExitStatus
fn to_string(self: &Self) -> String
impl<T, U> Into for ExitStatus
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for ExitStatus
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for ExitStatus
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>