pub struct CommandPipe { /* private fields */ }
Expand description
A type representing an anonymous pipe
Implementations§
Source§impl CommandPipe
impl CommandPipe
Sourcepub fn add_command<S>(&mut self, c: S) -> &mut Self
pub fn add_command<S>(&mut self, c: S) -> &mut Self
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");
Sourcepub fn arg<S>(&mut self, arg: S) -> &mut Self
pub fn arg<S>(&mut self, arg: S) -> &mut Self
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");
Sourcepub fn args<I, S>(&mut self, args: I) -> &mut Self
pub fn args<I, S>(&mut self, args: I) -> &mut Self
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"]);
Sourcepub fn spawn(&mut self) -> Result<(), APipeError>
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.");
Sourcepub fn spawn_with_output(&mut self) -> Result<Output, APipeError>
pub fn spawn_with_output(&mut self) -> Result<Output, APipeError>
Sourcepub fn output(&mut self) -> Result<Output, APipeError>
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
impl BitOr<Command> for CommandPipe
Source§impl Debug for CommandPipe
impl Debug for CommandPipe
Source§impl Default for CommandPipe
impl Default for CommandPipe
Source§fn default() -> CommandPipe
fn default() -> CommandPipe
Returns the “default value” for a type. Read more
Source§impl TryFrom<&str> for CommandPipe
impl TryFrom<&str> for CommandPipe
Source§type Error = APipeError
type Error = APipeError
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl Freeze for CommandPipe
impl !RefUnwindSafe for CommandPipe
impl Send for CommandPipe
impl Sync for CommandPipe
impl Unpin for CommandPipe
impl !UnwindSafe for CommandPipe
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