pub struct XXExpression { /* private fields */ }Implementations§
Source§impl XXExpression
impl XXExpression
pub fn stdout_capture(self) -> Self
pub fn stderr_capture(self) -> Self
pub fn arg(self, arg: impl Into<OsString>) -> Self
pub fn args(self, args: impl IntoIterator<Item = impl Into<OsString>>) -> Self
pub fn run(&self) -> XXResult<Output>
pub fn read(&self) -> XXResult<String>
Sourcepub fn on_stdout_line<F>(self, handler: F) -> Self
pub fn on_stdout_line<F>(self, handler: F) -> Self
Register a line-by-line stdout handler. When set, run() will stream output lines
to this handler instead of capturing stdout.
Sourcepub fn on_stderr_line<F>(self, handler: F) -> Self
pub fn on_stderr_line<F>(self, handler: F) -> Self
Register a line-by-line stderr handler. When set, run() will stream error lines
to this handler instead of capturing stderr.
Sourcepub fn env<K, V>(self, key: K, value: V) -> Self
pub fn env<K, V>(self, key: K, value: V) -> Self
Set an environment variable for this command
§Example
use xx::process;
let output = process::cmd("sh", ["-c", "echo $MY_VAR"])
.env("MY_VAR", "hello")
.read()
.unwrap();
assert_eq!(output, "hello");Sourcepub fn envs<I, K, V>(self, vars: I) -> Self
pub fn envs<I, K, V>(self, vars: I) -> Self
Set multiple environment variables for this command
§Example
use xx::process;
use std::collections::HashMap;
let mut env = HashMap::new();
env.insert("VAR1", "value1");
env.insert("VAR2", "value2");
let output = process::cmd("sh", ["-c", "echo $VAR1 $VAR2"])
.envs(env)
.read()
.unwrap();
assert_eq!(output, "value1 value2");Sourcepub fn env_clear(self) -> Self
pub fn env_clear(self) -> Self
Clear all environment variables before running (start with empty environment)
§Example
use xx::process;
let output = process::cmd("sh", ["-c", "echo ${PATH:-empty}"])
.env_clear()
.env("PATH", "/bin:/usr/bin")
.read()
.unwrap();
assert_eq!(output, "/bin:/usr/bin");Sourcepub fn cwd<P: AsRef<Path>>(self, dir: P) -> Self
pub fn cwd<P: AsRef<Path>>(self, dir: P) -> Self
Set the working directory for this command
§Example
use xx::process;
let output = process::cmd("pwd", Vec::<&str>::new())
.cwd("/tmp")
.read()
.unwrap();
assert!(output.contains("tmp"));Sourcepub fn stdin_bytes<B: AsRef<[u8]>>(self, data: B) -> Self
pub fn stdin_bytes<B: AsRef<[u8]>>(self, data: B) -> Self
Provide stdin data as bytes
§Example
use xx::process;
let output = process::cmd("cat", Vec::<&str>::new())
.stdin_bytes(b"hello world")
.read()
.unwrap();
assert_eq!(output, "hello world");Sourcepub fn stdin_file<P: AsRef<Path>>(self, path: P) -> XXResult<Self>
pub fn stdin_file<P: AsRef<Path>>(self, path: P) -> XXResult<Self>
Provide stdin data from a file
§Example
use xx::process;
let output = process::cmd("cat", Vec::<&str>::new())
.stdin_file("input.txt")
.unwrap()
.read()
.unwrap();Sourcepub fn unchecked(self) -> Self
pub fn unchecked(self) -> Self
Don’t check the exit status (allow non-zero exit codes)
By default, run() and read() return an error if the process exits
with a non-zero status. This method disables that check.
§Example
use xx::process;
// This would normally error because false exits with code 1
let output = process::cmd("false", Vec::<&str>::new())
.unchecked()
.run()
.unwrap();
assert!(!output.status.success());Trait Implementations§
Source§impl Default for XXExpression
impl Default for XXExpression
Source§fn default() -> XXExpression
fn default() -> XXExpression
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for XXExpression
impl !RefUnwindSafe for XXExpression
impl Send for XXExpression
impl Sync for XXExpression
impl Unpin for XXExpression
impl UnsafeUnpin for XXExpression
impl !UnwindSafe for XXExpression
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