pub struct CommandOutput { /* private fields */ }Expand description
Captured output and status information from a finished command.
CommandOutput always stores raw stdout and stderr bytes. By default,
Self::stdout and Self::stderr validate those bytes as UTF-8 and
return str::Utf8Error for invalid output. If the command was run with
CommandRunner::lossy_output enabled,
the runner also stores lossy UTF-8 text where invalid byte sequences are
replaced with the Unicode replacement character. This makes the text
accessors return Ok(&str) while preserving the original bytes through
Self::stdout_bytes and Self::stderr_bytes.
§Author
Haixing Hu
Implementations§
Source§impl CommandOutput
impl CommandOutput
Sourcepub const fn exit_code(&self) -> Option<i32>
pub const fn exit_code(&self) -> Option<i32>
Returns the command exit code.
§Returns
Some(code) when the platform reports a numeric process exit code, or
None when the process ended in a way that does not map to a numeric
code.
Sourcepub fn stdout(&self) -> Result<&str, Utf8Error>
pub fn stdout(&self) -> Result<&str, Utf8Error>
Returns captured standard output as UTF-8 text.
§Returns
Ok(&str) when stdout is valid UTF-8. If the command runner used lossy
output mode, this returns the stored lossy text even when the original
bytes were not valid UTF-8.
§Errors
Returns str::Utf8Error when stdout contains invalid UTF-8 and the
command runner did not enable lossy output mode.
Sourcepub fn stderr(&self) -> Result<&str, Utf8Error>
pub fn stderr(&self) -> Result<&str, Utf8Error>
Returns captured standard error as UTF-8 text.
§Returns
Ok(&str) when stderr is valid UTF-8. If the command runner used lossy
output mode, this returns the stored lossy text even when the original
bytes were not valid UTF-8.
§Errors
Returns str::Utf8Error when stderr contains invalid UTF-8 and the
command runner did not enable lossy output mode.
Sourcepub const fn elapsed(&self) -> Duration
pub const fn elapsed(&self) -> Duration
Returns the observed command duration.
§Returns
Duration from process spawn to observed termination.
Sourcepub fn stdout_bytes(&self) -> &[u8] ⓘ
pub fn stdout_bytes(&self) -> &[u8] ⓘ
Returns the captured standard output bytes.
§Returns
A borrowed slice containing stdout exactly as emitted by the process.
Sourcepub fn stderr_bytes(&self) -> &[u8] ⓘ
pub fn stderr_bytes(&self) -> &[u8] ⓘ
Returns the captured standard error bytes.
§Returns
A borrowed slice containing stderr exactly as emitted by the process.
Trait Implementations§
Source§impl Clone for CommandOutput
impl Clone for CommandOutput
Source§fn clone(&self) -> CommandOutput
fn clone(&self) -> CommandOutput
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more