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.
current_dir: Option<PathBuf>
Working directory of the child process.
stdin: Option<Stdio>
Configuration for the child process’s standard input (stdin) handle.
stdout: Option<Stdio>
Configuration for the child process’s standard output (stdout) handle.
stderr: Option<Stdio>
Configuration for the child process’s standard error (stderr) handle.
expand: bool
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
impl Command
Sourcepub fn new<S: ToString>(program: S) -> Self
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.
pub fn expand<'a>(&self, input: &'a str) -> Cow<'a, str>
expand
only.Sourcepub fn get_program(&self) -> Cow<'_, str>
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.
Sourcepub fn arg<S: ToString>(&mut self, arg: S) -> &mut Self
pub fn arg<S: ToString>(&mut self, arg: S) -> &mut Self
Adds an argument to pass to the program.
Sourcepub fn args<I, S>(&mut self, args: I) -> &mut Selfwhere
I: IntoIterator<Item = S>,
S: ToString,
pub fn args<I, S>(&mut self, args: I) -> &mut Selfwhere
I: IntoIterator<Item = S>,
S: ToString,
Adds multiple arguments to pass to the program.
Sourcepub fn get_args(&self) -> Option<Vec<Cow<'_, str>>>
pub fn get_args(&self) -> Option<Vec<Cow<'_, str>>>
Gets the arguments as str Cow
s.
If the expand
cargo feature is enabled, and
Command::expand
is true, then arguments are also
shell-expanded.
Sourcepub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
Inserts or updates an explicit environment variable mapping.
Sourcepub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
Inserts or updates multiple explicit environment variable mappings.
Sourcepub fn env_remove<K: AsRef<str>>(&mut self, key: K) -> &mut Self
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.
Sourcepub fn env_clear(&mut self) -> &mut Self
pub fn env_clear(&mut self) -> &mut Self
Clears all explicitly set environment variables and prevents inheriting any parent process environment variables.
Sourcepub fn current_dir<P: Into<PathBuf>>(&mut self, dir: P) -> &mut Self
pub fn current_dir<P: Into<PathBuf>>(&mut self, dir: P) -> &mut Self
Sets the working directory for the child process.
Sourcepub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command
Configuration for the child process’s standard input (stdin) handle.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Command
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Command
serde
only.Source§fn deserialize<D: Deserializer<'de>>(
deserializer: D,
) -> Result<Command, D::Error>
fn deserialize<D: Deserializer<'de>>( deserializer: D, ) -> Result<Command, D::Error>
Source§impl From<Command> for Command
Available on crate feature std
only.Converts a Command
builder to a std::process::Command
.
impl From<Command> for Command
std
only.Converts a Command
builder to a std::process::Command
.
Source§impl From<Command> for Command
Available on crate feature tokio
only.Converts a Command
builder to a std::process::Command
.
impl From<Command> for Command
tokio
only.Converts a Command
builder to a std::process::Command
.