Output in std::process - Rust (original) (raw)
Struct Output
1.0.0 · Source
pub struct Output {
pub status: ExitStatus,
pub stdout: Vec<u8>,
pub stderr: Vec<u8>,
}
Expand description
The status (exit code) of the process.
The data that the process wrote to stdout.
The data that the process wrote to stderr.
🔬This is a nightly-only experimental API. (exit_status_error
#84908)
Returns an error if a nonzero exit status was received.
If the Command exited successfully,self
is returned.
This is equivalent to calling exit_okon 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
#![feature(exit_status_error)]
use std::process::Command;
assert!(Command::new("false").output().unwrap().exit_ok().is_err());
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient, and should not be overridden without very good reason.