pub struct ShellOutput {
pub code: Option<i32>,
pub stdout: Vec<u8>,
pub stderr: Vec<u8>,
}
Expand description
Representation of the output of a command executed in an IShell.
The ShellOutput
struct holds the results of a command that was run through a shell,
including the exit code, standard output, and standard error output.
§Examples
use ishell::{IShell, ShellOutput};
let shell = IShell::new();
let shell_output = shell.run_command("true");
// equivalent of `shell_output.code.unwrap() == 0`
assert!(shell_output.is_success());
assert!(shell_output.stdout.is_empty());
assert!(shell_output.stderr.is_empty());
use ishell::{IShell, ShellOutput};
let shell = IShell::new();
let result = shell.run_command("echo 'Hello, world!'");
assert!(result.is_success());
let target_result =
String::from_utf8(result.stdout).expect("Stdout contained invalid UTF-8!");
assert_eq!(target_result, "Hello, world!");
assert!(result.stderr.is_empty());
Fields§
§code: Option<i32>
An optional exit code returned by the command.
- If the command executed successfully, this will typically be
0
. - If the command failed or was terminated, this will contain a non-zero value.
- If the command did not return an exit code, this will be
None
.
stdout: Vec<u8>
A vector of bytes containing the standard output produced by the command.
- This field captures any output that the command printed to the standard output stream (if any).
stderr: Vec<u8>
A vector of bytes containing the standard error output produced by the command.
- This field captures any error messages or diagnostics that the command printed to the standard error stream.
Implementations§
Source§impl ShellOutput
impl ShellOutput
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if output indicates a command was successful
The check is done by comparing to 0. If no output is found, returns false
Auto Trait Implementations§
impl Freeze for ShellOutput
impl RefUnwindSafe for ShellOutput
impl Send for ShellOutput
impl Sync for ShellOutput
impl Unpin for ShellOutput
impl UnwindSafe for ShellOutput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more