pub struct Command { /* private fields */ }
Implementations§
Source§impl Command
impl Command
Sourcepub fn arg_would_fit<S: AsRef<OsStr>>(&self, arg: S) -> bool
pub fn arg_would_fit<S: AsRef<OsStr>>(&self, arg: S) -> bool
Check if an additional argument would fit in the command.
Sourcepub fn args_would_fit<I, S>(&self, args: I) -> bool
pub fn args_would_fit<I, S>(&self, args: I) -> bool
Check if multiple additional arguments would all fit in the command.
Sourcepub fn try_arg<S: AsRef<OsStr>>(&mut self, arg: S) -> Result<&mut Self>
pub fn try_arg<S: AsRef<OsStr>>(&mut self, arg: S) -> Result<&mut Self>
Like std::process::Command::arg
, add an argument to the
command, but only if it will fit.
Sourcepub fn try_args<I, S>(&mut self, args: I) -> Result<&mut Self>
pub fn try_args<I, S>(&mut self, args: I) -> Result<&mut Self>
Like std::process::Command::arg
, add multiple arguments to
the command, but only if they will all fit.
Sourcepub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self
Sourcepub fn status(&mut self) -> Result<ExitStatus>
pub fn status(&mut self) -> Result<ExitStatus>
Methods from Deref<Target = Command>§
1.57.0 · Sourcepub fn get_program(&self) -> &OsStr
pub fn get_program(&self) -> &OsStr
Returns the path to the program that was given to Command::new
.
§Examples
use std::process::Command;
let cmd = Command::new("echo");
assert_eq!(cmd.get_program(), "echo");
1.57.0 · Sourcepub fn get_args(&self) -> CommandArgs<'_>
pub fn get_args(&self) -> CommandArgs<'_>
Returns an iterator of the arguments that will be passed to the program.
This does not include the path to the program as the first argument;
it only includes the arguments specified with Command::arg
and
Command::args
.
§Examples
use std::ffi::OsStr;
use std::process::Command;
let mut cmd = Command::new("echo");
cmd.arg("first").arg("second");
let args: Vec<&OsStr> = cmd.get_args().collect();
assert_eq!(args, &["first", "second"]);
1.57.0 · Sourcepub fn get_envs(&self) -> CommandEnvs<'_>
pub fn get_envs(&self) -> CommandEnvs<'_>
Returns an iterator of the environment variables explicitly set for the child process.
Environment variables explicitly set using Command::env
, Command::envs
, and
Command::env_remove
can be retrieved with this method.
Note that this output does not include environment variables inherited from the parent process.
Each element is a tuple key/value pair (&OsStr, Option<&OsStr>)
. A None
value
indicates its key was explicitly removed via Command::env_remove
. The associated key for
the None
value will no longer inherit from its parent process.
An empty iterator can indicate that no explicit mappings were added or that
Command::env_clear
was called. After calling Command::env_clear
, the child process
will not inherit any environment variables from its parent process.
§Examples
use std::ffi::OsStr;
use std::process::Command;
let mut cmd = Command::new("ls");
cmd.env("TERM", "dumb").env_remove("TZ");
let envs: Vec<(&OsStr, Option<&OsStr>)> = cmd.get_envs().collect();
assert_eq!(envs, &[
(OsStr::new("TERM"), Some(OsStr::new("dumb"))),
(OsStr::new("TZ"), None)
]);
1.57.0 · Sourcepub fn get_current_dir(&self) -> Option<&Path>
pub fn get_current_dir(&self) -> Option<&Path>
Returns the working directory for the child process.
This returns None
if the working directory will not be changed.
§Examples
use std::path::Path;
use std::process::Command;
let mut cmd = Command::new("ls");
assert_eq!(cmd.get_current_dir(), None);
cmd.current_dir("/bin");
assert_eq!(cmd.get_current_dir(), Some(Path::new("/bin")));