Struct ShellOutput

Source
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

Source

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§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.