pub struct ExitStatus(/* private fields */);
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.
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.
impl ExitStatus
pub fn exit_ok(&self) -> Result<(), ExitStatusError>
exit_status_error #84908)
Was termination successful? Returns a Result.
#![feature(exit_status_error)]
use std::process::Command;
let status = Command::new("ls")
.arg("/dev/nonexistent")
.status()
.expect("ls could not be executed");
println!("ls: {status}");
status.exit_ok().expect_err("/dev/nonexistent could be listed!");pub fn success(&self) -> bool
Was termination successful? Signal termination is not considered a success, and success is defined as a zero exit status.
use std::process::Command;
let status = Command::new("mkdir")
.arg("projects")
.status()
.expect("failed to execute mkdir");
if status.success() {
println!("'projects/' directory created");
} else {
println!("failed to create 'projects/' directory: {status}");
}pub fn 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 calling exit. Note that on Unix the exit status is truncated to 8 bits, and that values that didn’t come from a program’s call to exit may be invented by the runtime system (often, for example, 255, 254, 127 or 126).
On Unix, this will return None if the process was terminated by a signal. ExitStatusExt is an extension trait for extracting any such signal, and other details, from the ExitStatus.
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) -> ExitStatus
fn clone_from(&mut self, source: &Self)
source. Read more
impl Debug for ExitStatus
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for ExitStatusThe default value is one which indicates successful completion.
impl Display for ExitStatus
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl ExitStatusExt for ExitStatusAvailable on Unix only.
fn from_raw(raw: i32) -> Self
ExitStatus or ExitStatusError from the raw underlying integer status value from wait Read more
fn signal(&self) -> Option<i32>
fn core_dumped(&self) -> bool
fn stopped_signal(&self) -> Option<i32>
fn continued(&self) -> bool
fn into_raw(self) -> i32
wait status. Read more
impl ExitStatusExt for ExitStatusAvailable on Windows only.
fn from_raw(raw: u32) -> Self
ExitStatus from the raw underlying u32 return value of a process.impl From<ExitStatusError> for ExitStatus
fn from(error: ExitStatusError) -> Self
impl PartialEq for ExitStatus
fn eq(&self, other: &ExitStatus) -> bool
self and other values to be equal, and is used by ==.fn ne(&self, other: &Rhs) -> bool
!=. The default implementation is almost always sufficient, and should not be overridden without very good reason.impl Copy for ExitStatus
impl Eq for ExitStatus
impl StructuralPartialEq for ExitStatus
impl Freeze for ExitStatus
impl RefUnwindSafe for ExitStatus
impl Send for ExitStatus
impl Sync for ExitStatus
impl Unpin for ExitStatus
impl UnwindSafe for ExitStatus
impl<T> Any for Twhere
T: 'static + ?Sized,impl<T> Borrow<T> for Twhere
T: ?Sized,impl<T> BorrowMut<T> for Twhere
T: ?Sized,impl<T> CloneToUninit for Twhere
T: Clone,unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit #126799)
impl<T> From<T> for T
fn from(t: T) -> T
Returns the argument unchanged.
impl<T, U> Into<U> for Twhere
U: From<T>,fn into(self) -> U
Calls U::from(self).
That is, this conversion is whatever the implementation of From<T> for U chooses to do.
impl<T> ToOwned for Twhere
T: Clone,type Owned = T
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)
impl<T> ToString for Twhere
T: Display + ?Sized,impl<T, U> TryFrom<U> for Twhere
U: Into<T>,type Error = Infallible
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/process/struct.ExitStatus.html