Skip to main content

XXExpression

Struct XXExpression 

Source
pub struct XXExpression { /* private fields */ }

Implementations§

Source§

impl XXExpression

Source

pub fn stdout_capture(self) -> Self

Source

pub fn stderr_capture(self) -> Self

Source

pub fn arg(self, arg: impl Into<OsString>) -> Self

Source

pub fn args(self, args: impl IntoIterator<Item = impl Into<OsString>>) -> Self

Source

pub fn run(&self) -> XXResult<Output>

Source

pub fn read(&self) -> XXResult<String>

Source

pub fn on_stdout_line<F>(self, handler: F) -> Self
where F: Fn(&str) + Send + Sync + 'static,

Register a line-by-line stdout handler. When set, run() will stream output lines to this handler instead of capturing stdout.

Source

pub fn on_stderr_line<F>(self, handler: F) -> Self
where F: Fn(&str) + Send + Sync + 'static,

Register a line-by-line stderr handler. When set, run() will stream error lines to this handler instead of capturing stderr.

Source

pub fn env<K, V>(self, key: K, value: V) -> Self
where K: Into<OsString>, V: Into<OsString>,

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");
Source

pub fn envs<I, K, V>(self, vars: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: Into<OsString>, V: Into<OsString>,

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");
Source

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");
Source

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"));
Source

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");
Source

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();
Source

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

Source§

fn default() -> XXExpression

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

impl Display for XXExpression

Source§

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

Formats the value using the given formatter. Read more

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V