PipeCommand

Struct PipeCommand 

Source
pub struct PipeCommand<const N: usize> {
    pub commands: [Command; N],
}
Expand description

Multiple commands that will be piped.

A PipeCommand can be created by either using the new method or by using the cmd! macro.

§Examples

Using the new method combined with Command::new and a simple use of the cmd! macro:

use procmd::{cmd, PipeCommand};
use std::process::Command;

let mut pipe_cmd = PipeCommand::new([Command::new("ls"), cmd!("grep", "example")]);
let child = pipe_cmd.spawn()?;

Using the cmd! macro with the => token to generate a PipeCommand and calling the status method to get the exit status:

use procmd::cmd;

let mut pipe_cmd = cmd!("ls" => "grep", "example");
let exit_status = pipe_cmd.status()?;

Fields§

§commands: [Command; N]

The commands.

Implementations§

Source§

impl<const N: usize> PipeCommand<N>

Source

pub fn new(commands: [Command; N]) -> Self

Creates a new PipeCommand.

Source

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

Spawns all commands and returns the Child of the last command.

§Panics

This method panics if commands is empty.

Examples found in repository?
examples/pipe.rs (line 5)
3fn main() {
4    let mut pipe_cmd = cmd!("ls", "/" => "grep", "bin");
5    let child = pipe_cmd.spawn().unwrap();
6}
Source

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

Returns the Output of the last command.

Note that this method still calls Command::spawn on all commands except the last one.

§Panics

This method panics if commands is empty.

Source

pub fn status(&mut self) -> Result<ExitStatus>

Returns the ExitStatus of the last command.

Note that this method still calls Command::spawn on all commands except the last one.

§Panics

This method panics if commands is empty.

Trait Implementations§

Source§

impl<const N: usize> Debug for PipeCommand<N>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for PipeCommand<N>

§

impl<const N: usize> !RefUnwindSafe for PipeCommand<N>

§

impl<const N: usize> Send for PipeCommand<N>

§

impl<const N: usize> Sync for PipeCommand<N>

§

impl<const N: usize> Unpin for PipeCommand<N>

§

impl<const N: usize> !UnwindSafe for PipeCommand<N>

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.