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§
Sourcefn cross_exec(&mut self) -> Error
fn cross_exec(&mut self) -> Error
On Unix, this will call std::os::unix::process::CommandExt::exec.
On Windows, this will:
- Set a
Ctrl+Cand friends handler that lets the child process handle them. - Run the command with
Command::status. If it fails to start, return the error. - Call
process::exitwith 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.