pub struct Pipeline { /* private fields */ }Expand description
A builder for creating command pipelines.
§Example
use bare_script::sync::Pipeline;
#[cfg(not(windows))]
{
let output = Pipeline::new("echo")
.arg("hello world")
.pipe("grep")
.arg("hello")
.execute();
assert!(output.is_ok());
}Implementations§
Source§impl Pipeline
impl Pipeline
Sourcepub fn new<S: AsRef<OsStr>>(program: S) -> Self
pub fn new<S: AsRef<OsStr>>(program: S) -> Self
Creates a new pipeline starting with the specified program.
Sourcepub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self
pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self
Adds an argument to the last command in the pipeline.
Sourcepub fn args<I, S>(self, args: I) -> Self
pub fn args<I, S>(self, args: I) -> Self
Adds multiple arguments to the last command in the pipeline.
Sourcepub fn pipe<S: AsRef<OsStr>>(self, program: S) -> Self
pub fn pipe<S: AsRef<OsStr>>(self, program: S) -> Self
Adds a new command to the pipeline, piping the output of the previous command to the stdin of this command.
§Errors
Returns an error if the previous command’s stdout could not be configured for piping.
Sourcepub fn env<K, V>(self, key: K, value: V) -> Self
pub fn env<K, V>(self, key: K, value: V) -> Self
Sets an environment variable for all commands in the pipeline.
Sourcepub fn current_dir<D>(self, dir: D) -> Self
pub fn current_dir<D>(self, dir: D) -> Self
Sets the working directory for all commands in the pipeline.
Sourcepub fn capture_output(self) -> Self
pub fn capture_output(self) -> Self
Configures the pipeline to capture the final output.
This must be called before execute() to capture stdout/stderr.
Sourcepub fn execute(&mut self) -> ScriptResult<Output>
pub fn execute(&mut self) -> ScriptResult<Output>
Executes the pipeline and returns the output of the final command.
§Errors
Returns an error if any command in the pipeline fails to execute.