Struct ExitStatus
pub struct ExitStatus(pub(in ::process) 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.
Fields
0: ExitStatus
Implementations
impl ExitStatus
fn exit_ok(&self) -> Result<(), ExitStatusError>Was termination successful? Returns a
Result.Examples
# if cfg! // cfg!(unix)fn success(&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) -> 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("mkdir command should execute successfully"); match status.code() { Some(code) => println!("Exited with status code: {code}"), None => println!("Process terminated by signal") }
Trait Implementations
impl AsInner<ExitStatus> for ExitStatus
fn as_inner(&self) -> &ExitStatus
impl Clone for ExitStatus
fn clone(&self) -> ExitStatus
impl Copy for ExitStatus
impl Debug for ExitStatus
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for ExitStatus
fn default() -> Self
impl Display for ExitStatus
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for ExitStatus
fn assert_fields_are_eq(&self)
impl ExitStatusExt for ExitStatus
fn from_raw(raw: u32) -> Self
impl ExitStatusExt for ExitStatus
fn from_raw(raw: i32) -> Selffn signal(&self) -> Option<i32>fn core_dumped(&self) -> boolfn stopped_signal(&self) -> Option<i32>fn continued(&self) -> boolfn into_raw(self) -> i32
impl From<ExitStatusError> for ExitStatus
fn from(error: ExitStatusError) -> Self
impl FromInner<ExitStatus> for ExitStatus
fn from_inner(s: ExitStatus) -> ExitStatus
impl PartialEq for ExitStatus
fn eq(&self, other: &ExitStatus) -> bool
impl StructuralPartialEq for ExitStatus
impl TrivialClone for ExitStatus
Auto Trait Implementations
impl Freeze for ExitStatus
impl RefUnwindSafe for ExitStatus
impl Send for ExitStatus
impl Sync for ExitStatus
impl Unpin for ExitStatus
impl UnsafeUnpin for ExitStatus
impl UnwindSafe for ExitStatus
Blanket Implementations
impl<T> Any for ExitStatus
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for ExitStatus
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for ExitStatus
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for ExitStatus
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for ExitStatus
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for ExitStatus
where
T: Copy + Debug,
impl<T> SizeHint for ExitStatus
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for ExitStatus
impl<T> ToOwned for ExitStatus
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> ToString for ExitStatus
where
T: Display + ?Sized,
fn to_string(&self) -> String
impl<T, U> Into<U> for ExitStatus
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for ExitStatus
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for ExitStatus
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>