Struct Output

pub struct Output { pub status: ExitStatus, pub stdout: Vec<u8>, pub stderr: Vec<u8> }

The output of a finished process.

This is returned in a Result by either the output method of a Command, or the wait_with_output method of a Child process.

Fields

status: ExitStatus

The status (exit code) of the process.

stdout: Vec<u8>

The data that the process wrote to stdout.

stderr: Vec<u8>

The data that the process wrote to stderr.

Implementations

impl Output

fn exit_ok(self) -> Result<Self, ExitStatusError>

Returns an error if a nonzero exit status was received.

If the Command exited successfully, self is returned.

This is equivalent to calling exit_ok on Output.status.

Note that this will throw away the Output::stderr field in the error case. If the child process outputs useful informantion to stderr, you can:

  • Use cmd.stderr(Stdio::inherit()) to forward the stderr child process to the parent's stderr, usually printing it to console where the user can see it. This is usually correct for command-line applications.
  • Capture stderr using a custom error type. This is usually correct for libraries.

Examples

# #![allow(unused_features)]
#![feature(exit_status_error)]
# #[cfg(all(unix, not(target_os = "android"), not(all(target_vendor = "apple", not(target_os = "macos")))))] {
use std::process::Command;
assert!(Command::new("false").output().unwrap().exit_ok().is_err());
# }

Trait Implementations

impl Clone for Output

fn clone(&self) -> Self

impl Debug for Output

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

impl Eq for Output

fn assert_fields_are_eq(&self)

impl PartialEq for Output

fn eq(&self, other: &Self) -> bool

impl StructuralPartialEq for Output

Auto Trait Implementations

impl Freeze for Output

impl RefUnwindSafe for Output

impl Send for Output

impl Sync for Output

impl Unpin for Output

impl UnsafeUnpin for Output

impl UnwindSafe for Output

Blanket Implementations

impl<T> Any for Output where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Output where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Output where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Output where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Output

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for Output where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Output

impl<T> ToOwned for Output where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Output where 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, U> TryFrom<U> for Output where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Output where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>