Command

Trait Command 

Source
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§

Source

type Child: Child

A spawned child process.

Required Methods§

Source

fn new<S>(program: S) -> Self
where S: AsRef<OsStr>,

Constructs a new Command for launching program.

The initial configuration (the working directory and environment variables) is inherited from the current process.

Source

fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self

Adds a single argument to pass to the program.

Source

fn args<I, S>(&mut self, args: I) -> &mut Self
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Adds multiple arguments to pass to the program.

Source

fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
where K: AsRef<OsStr>, V: AsRef<OsStr>,

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.

Source

fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

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.

Source

fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self

Removes an environment variable mapping.

Source

fn env_clear(&mut self) -> &mut Self

Removes all environment variable mappings.

Source

fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self

Configures the working directory for the new process.

Source

fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Configures the standard input (stdin) for the new process.

Source

fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Configures the standard output (stdout) for the new process.

Source

fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self

Configures the standard error (stderr) for the new process.

Source

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.

Source

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().

Source

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().

Source

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().

Source

fn uid(&mut self, id: u32) -> &mut Self

Available on Unix only.

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.

Source

fn gid(&mut self, id: u32) -> &mut Self

Available on Unix only.

Similar to uid, but sets the group ID of the child process. This has the same semantics as the uid field.

Source

fn exec(&mut self) -> Error

Available on Unix only.

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.

Source

fn arg0<S>(&mut self, arg: S) -> &mut Self
where S: AsRef<OsStr>,

Available on Unix only.

Set executable argument

Set the first process argument, argv[0], to something other than the default executable path.

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.

Implementors§