Struct CommandPipe

Source
pub struct CommandPipe { /* private fields */ }
Expand description

A type representing an anonymous pipe

Implementations§

Source§

impl CommandPipe

Source

pub fn new() -> Self

Create a new empty pipe.

§Example
let mut pipe = CommandPipe::new();
Source

pub fn add_command<S>(&mut self, c: S) -> &mut Self
where S: AsRef<OsStr>,

Add a command to the pipe.

The command is passed eiter as an absolute path or as a relative path. For relative paths the PATH is checked.

§Example
let mut pipe = CommandPipe::new();
pipe.add_command("ls");
Source

pub fn arg<S>(&mut self, arg: S) -> &mut Self
where S: AsRef<OsStr>,

Add a single argument to the preceding command in the pipe.

Arguments need to be passed one at a time.

§Example
let mut pipe = CommandPipe::new();
pipe.add_command("ls").arg("-la");
Source

pub fn args<I, S>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Add multiple arguments to the preceding command in the pipe.

Arguments are passed as a sequence.

§Example
let mut pipe = CommandPipe::new();
pipe.add_command("ls").args(vec!["-la", "~/Documents"]);
Source

pub fn spawn(&mut self) -> Result<(), APipeError>

Runs the commands in the pipe.

§Example
let mut pipe = CommandPipe::new();
pipe.add_command("ls")
    .args(vec!["-la", "~/Documents"])
    .add_command("grep")
    .arg("My_Dir")
    .spawn()
    .expect("Failed to spawn pipe.");
Source

pub fn spawn_with_output(&mut self) -> Result<Output, APipeError>

Spawns all commands in the pipe and returns the Output.

§Example
let output = CommandPipe::new()
    .add_command("echo")
    .arg("This is a test.")
    .add_command("grep")
    .arg("-Eo")
    .arg(r"\w\w\sa[^.]*")
    .spawn_with_output()?;

assert_eq!(output.stdout(), "is a test\n".as_bytes());
Source

pub fn output(&mut self) -> Result<Output, APipeError>

Returns the Output of the pipe.

§Example
let mut pipe = apipe::CommandPipe::new();

pipe.add_command("echo")
    .arg("This is a test.")
    .add_command("grep")
    .arg("-Eo")
    .arg(r"\w\w\sa[^.]*")
    .spawn()
    .expect("Failed to spawn pipe.");
     
let output = pipe.output().unwrap();
     
assert_eq!(output.stdout(), "is a test\n".as_bytes());

Trait Implementations§

Source§

impl BitOr<Command> for CommandPipe

Source§

type Output = CommandPipe

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Command) -> Self

Performs the | operation. Read more
Source§

impl Debug for CommandPipe

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CommandPipe

Source§

fn default() -> CommandPipe

Returns the “default value” for a type. Read more
Source§

impl TryFrom<&str> for CommandPipe

Source§

type Error = APipeError

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

fn try_from(value: &str) -> Result<Self, APipeError>

Performs the conversion.

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.