pub struct Command {
    pub name: OsString,
    pub arguments: Vec<OsString>,
    pub inherit_environment: bool,
    pub environment: HashMap<OsString, Option<OsString>>,
    pub current_dir: Option<PathBuf>,
    pub stdin: Option<Stdio>,
    pub stdout: Option<Stdio>,
    pub stderr: Option<Stdio>,
}
Expand description

A process builder, providing fine-grained control over how a new process should be spawned. Equivalent to std’s Command but allowing field access cloning and serialization.

Fields§

§name: OsString

Name of the program invoked.

§arguments: Vec<OsString>

Arguments passed to the child process.

§inherit_environment: bool

Controlls whether the child process will inherit the parent process’ environment.

§environment: HashMap<OsString, Option<OsString>>

Environment for the child process, None represents variables that will not be inherited from the parent, even when inherit_environment == true.

§current_dir: Option<PathBuf>

Working directory for the child process.

§stdin: Option<Stdio>

Child process’ standard input (stdin) handle, None will use default for invocation type.

§stdout: Option<Stdio>

Child process’ standard output (stdout) handle, None will use default for invocation type.

§stderr: Option<Stdio>

Child process’ standard error (stderr) handle, None will use default for invocation type.

Implementations§

source§

impl Command

Builder

source

pub fn new(name: impl AsRef<OsStr>) -> Self

Constructs a new Command. more

source

pub fn arg(self, arg: impl AsRef<OsStr>) -> Self

Adds an argument to pass to the program. more

source

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

Adds multiple arguments to pass to the program. more

source

pub fn env(self, key: impl AsRef<OsStr>, val: impl AsRef<OsStr>) -> Self

Inserts or updates an environment variable. more

source

pub fn envs( self, vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)> ) -> Self

Inserts or updates multiple environment variables. more

source

pub fn env_remove(self, key: impl AsRef<OsStr>) -> Self

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

source

pub fn env_clear(self) -> Self

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

source

pub fn env_no_inherit(self) -> Self

Prevents inheriting any parent process environment variables (like env_clear without clearing set envs).

source

pub fn current_dir(self, key: impl AsRef<Path>) -> Self

Sets the working directory for the child process. more

source

pub fn stdin(self, stdin: Stdio) -> Self

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

source

pub fn stdout(self, stdout: Stdio) -> Self

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

source

pub fn stderr(self, stderr: Stdio) -> Self

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

source§

impl Command

Setters

source

pub fn add_arg(&mut self, arg: impl AsRef<OsStr>)

Adds an argument to pass to the program. more

source

pub fn add_args(&mut self, args: impl IntoIterator<Item = impl AsRef<OsStr>>)

Adds multiple arguments to pass to the program. more

source

pub fn set_env(&mut self, key: impl AsRef<OsStr>, val: impl AsRef<OsStr>)

Inserts or updates an environment variable. more

source

pub fn set_envs( &mut self, vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)> )

Inserts or updates multiple environment variables. more

source

pub fn remove_env(&mut self, key: impl AsRef<OsStr>)

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

source

pub fn set_current_dir(&mut self, path: impl AsRef<Path>)

Sets the working directory for the child process. more

source§

impl Command

Execution

source

pub fn spawn(&self) -> Result<Child>

Behaves identical to std’s Command::spawn.

source

pub fn output(&self) -> Result<Output>

Behaves identical to std’s Command::output.

source

pub fn status(&self) -> Result<ExitStatus>

Behaves identical to std’s Command::status.

source

pub fn to_std(&self) -> StdCommand

Convert this command to a std::process::Command.

Trait Implementations§

source§

impl Clone for Command

source§

fn clone(&self) -> Command

Returns a copy 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 From<&Command> for Command

source§

fn from(_: &Command) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Command

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Command

source§

impl StructuralPartialEq 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> 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,

§

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>,

§

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>,

§

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.