CommandExt

Trait CommandExt 

Source
pub trait CommandExt: Sealed {
    // Required method
    fn cross_exec(&mut self) -> Error;
}
Expand description

Extensions to the process::Command builder.

This trait is sealed: it cannot be implemented outside cross_exec. This is so that future additional methods are not breaking changes.

Required Methods§

Source

fn cross_exec(&mut self) -> Error

On Unix, this will call std::os::unix::process::CommandExt::exec.

On Windows, this will:

  1. Set a Ctrl+C and friends handler that lets the child process handle them.
  2. Run the command with Command::status. If it fails to start, return the error.
  3. Call process::exit with the exit code of the child process.

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.

cross_exec not returning has the same implications as calling process::exit – no destructors on the current stack or any other thread’s stack will be run. Therefore, it is recommended to only call cross_exec at a point where it is fine to not run any destructors.

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 inherit them 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.

Implementations on Foreign Types§

Source§

impl CommandExt for Command

Source§

fn cross_exec(&mut self) -> Error

Implementors§