Struct Command

Source
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<'de> Deserialize<'de> for Command

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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

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

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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> 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>,