Struct Command

Source
pub struct Command {
    pub envs: Option<HashMap<String, String>>,
    pub current_dir: Option<PathBuf>,
    pub stdin: Option<Stdio>,
    pub stdout: Option<Stdio>,
    pub stderr: Option<Stdio>,
    pub expand: bool,
    /* private fields */
}
Expand description

The command builder.

The aim of this builder is to be able to declare a command using the same API from std::process::Command, without any I/O interaction. I/O connectors can then take data from this builder to build I/O-specific commands.

Refs: std::process::Command

Fields§

§envs: Option<HashMap<String, String>>

Environment variables explicitly set for the child process.

Refs: std::process::Command::get_envs

§current_dir: Option<PathBuf>

Working directory of the child process.

Refs: std::process::Command::get_current_dir

§stdin: Option<Stdio>

Configuration for the child process’s standard input (stdin) handle.

Refs: std::process::Command::stdin

§stdout: Option<Stdio>

Configuration for the child process’s standard output (stdout) handle.

Refs: std::process::Command::stdout

§stderr: Option<Stdio>

Configuration for the child process’s standard error (stderr) handle.

Refs: std::process::Command::stderr

§expand: bool
Available on crate feature expand only.

Should shell-expand program and arguments.

When true, tilde ~ and environment variables $ENV are expanded for the program and arguments only.

Requires the expand cargo feature.

Implementations§

Source§

impl Command

Source

pub fn new<S: ToString>(program: S) -> Self

Constructs a new Command for launching the program at path program. This is just a builder, it does not launch any program on its own. Only I/O connectors do spawn processes.

Refs: std::process::Command::new

Source

pub fn expand<'a>(&self, input: &'a str) -> Cow<'a, str>

Available on crate feature expand only.
Source

pub fn get_program(&self) -> Cow<'_, str>

Gets the program as str Cow.

If the expand cargo feature is enabled, and Command::expand is true, then program is also shell-expanded.

Source

pub fn arg<S: ToString>(&mut self, arg: S) -> &mut Self

Adds an argument to pass to the program.

Refs: std::process::Command::arg

Source

pub fn args<I, S>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = S>, S: ToString,

Adds multiple arguments to pass to the program.

Refs: std::process::Command::args

Source

pub fn get_args(&self) -> Option<Vec<Cow<'_, str>>>

Gets the arguments as str Cows.

If the expand cargo feature is enabled, and Command::expand is true, then arguments are also shell-expanded.

Source

pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
where K: ToString, V: ToString,

Inserts or updates an explicit environment variable mapping.

Refs: std::process::Command::env

Source

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

Inserts or updates multiple explicit environment variable mappings.

Refs: std::process::Command::envs

Source

pub fn env_remove<K: AsRef<str>>(&mut self, key: K) -> &mut Self

Removes an explicitly set environment variable and prevents inheriting it from a parent process.

Refs: std::process::Command::env_remove

Source

pub fn env_clear(&mut self) -> &mut Self

Clears all explicitly set environment variables and prevents inheriting any parent process environment variables.

Refs: std::process::Command::env_clear

Source

pub fn current_dir<P: Into<PathBuf>>(&mut self, dir: P) -> &mut Self

Sets the working directory for the child process.

Refs: std::process::Command::current_dir

Source

pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command

Configuration for the child process’s standard input (stdin) handle.

Refs: std::process::Command::stdin

Source

pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command

Configuration for the child process’s standard output (stdout) handle.

Refs: std::process::Command::stdout

Source

pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command

Configuration for the child process’s standard error (stderr) handle.

Refs: std::process::Command::stderr

Trait Implementations§

Source§

impl Clone for Command

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Command

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Command

Source§

fn default() -> Command

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

impl<'de> Deserialize<'de> for Command

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>( deserializer: D, ) -> Result<Command, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Command> for Command

Available on crate feature std only.

Converts a Command builder to a std::process::Command.

Source§

fn from(builder: Command) -> Self

Converts to this type from the input type.
Source§

impl From<Command> for Command

Available on crate feature tokio only.

Converts a Command builder to a std::process::Command.

Source§

fn from(builder: Command) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Command

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Command

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Command

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,