pub trait Command: Sized + From<Command> {
type Child: Child;
Show 19 methods
// Required methods
fn new<S>(program: S) -> Self
where S: AsRef<OsStr>;
fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self;
fn args<I, S>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = S>,
S: AsRef<OsStr>;
fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
where K: AsRef<OsStr>,
V: AsRef<OsStr>;
fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
where I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>;
fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self;
fn env_clear(&mut self) -> &mut Self;
fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self;
fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self;
fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self;
fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self;
fn kill_on_drop(&mut self, kill_on_drop: bool) -> &mut Self;
fn spawn(&mut self) -> Result<Self::Child>;
fn status(&mut self) -> impl Future<Output = Result<ExitStatus>> + Send;
fn output(&mut self) -> impl Future<Output = Result<Output>> + Send;
fn uid(&mut self, id: u32) -> &mut Self;
fn gid(&mut self, id: u32) -> &mut Self;
fn exec(&mut self) -> Error;
fn arg0<S>(&mut self, arg: S) -> &mut Self
where S: AsRef<OsStr>;
}Expand description
An abstraction of a builder for spawning processes.
Required Associated Types§
Required Methods§
Sourcefn new<S>(program: S) -> Self
fn new<S>(program: S) -> Self
Constructs a new Command for launching program.
The initial configuration (the working directory and environment variables) is inherited from the current process.
Sourcefn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self
fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self
Adds a single argument to pass to the program.
Sourcefn env<K, V>(&mut self, key: K, val: V) -> &mut Self
fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
Configures an environment variable for the new process.
Note that environment variable names are case-insensitive (but case-preserving) on Windows, and case-sensitive on all other platforms.
Sourcefn envs<I, K, V>(&mut self, vars: I) -> &mut Self
fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
Configures multiple environment variables for the new process.
Note that environment variable names are case-insensitive (but case-preserving) on Windows, and case-sensitive on all other platforms.
Sourcefn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self
fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self
Removes an environment variable mapping.
Sourcefn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self
fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self
Configures the working directory for the new process.
Sourcefn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Configures the standard input (stdin) for the new process.
Sourcefn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Configures the standard output (stdout) for the new process.
Sourcefn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Configures the standard error (stderr) for the new process.
Sourcefn kill_on_drop(&mut self, kill_on_drop: bool) -> &mut Self
fn kill_on_drop(&mut self, kill_on_drop: bool) -> &mut Self
Configures whether to kill the process when Child is dropped.
The default value of this option is false.
Sourcefn spawn(&mut self) -> Result<Self::Child>
fn spawn(&mut self) -> Result<Self::Child>
Executes the command and returns the Child handle to it.
If not configured, stdin, stdout and stderr will be set to Stdio::inherit().
Sourcefn status(&mut self) -> impl Future<Output = Result<ExitStatus>> + Send
fn status(&mut self) -> impl Future<Output = Result<ExitStatus>> + Send
Executes the command, waits for it to exit, and returns the exit status.
If not configured, stdin, stdout and stderr will be set to Stdio::inherit().
Sourcefn output(&mut self) -> impl Future<Output = Result<Output>> + Send
fn output(&mut self) -> impl Future<Output = Result<Output>> + Send
Executes the command and collects its output.
If not configured, stdin will be set to Stdio::null(), and stdout and stderr will be
set to Stdio::piped().
Sourcefn uid(&mut self, id: u32) -> &mut Self
Available on Unix only.
fn uid(&mut self, id: u32) -> &mut Self
Sets the child process’s user ID. This translates to a
setuid call in the child process. Failure in the setuid
call will cause the spawn to fail.
Sourcefn gid(&mut self, id: u32) -> &mut Self
Available on Unix only.
fn gid(&mut self, id: u32) -> &mut Self
Similar to uid, but sets the group ID of the child process. This has
the same semantics as the uid field.
Sourcefn exec(&mut self) -> Error
Available on Unix only.
fn exec(&mut self) -> Error
Performs all the required setup by this Command, followed by calling
the execvp syscall.
On success this function will not return, and otherwise it will return
an error indicating why the exec (or another part of the setup of the
Command) failed.
exec not returning has the same implications as calling
std::process::exit – no destructors on the current stack or any other
thread’s stack will be run. Therefore, it is recommended to only call
exec at a point where it is fine to not run any destructors. Note,
that the execvp syscall independently guarantees that all memory is
freed and all file descriptors with the CLOEXEC option (set by default
on all file descriptors opened by the standard library) are closed.
This function, unlike spawn, will not fork the process to create
a new child. Like spawn, however, the default behavior for the stdio
descriptors will be to inherited from the current process.
§Notes
The process may be in a “broken state” if this function returns in
error. For example the working directory, environment variables, signal
handling settings, various user/group information, or aspects of stdio
file descriptors may have changed. If a “transactional spawn” is
required to gracefully handle errors it is recommended to use the
cross-platform spawn instead.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.