std::os::unix::process::CommandExt - Rust
Description: API documentation for the Rust `CommandExt` trait in crate `std`.
Keywords: rust, rustlang, rust-lang, CommandExt

# Trait std::os::unix::process::CommandExt 1.0.0 [−] [src]

    pub trait CommandExt {
        fn uid(&mut self, id: u32) -> &mut Command;
        fn gid(&mut self, id: u32) -> &mut Command;
        fn before_exec<F>(&mut self, f: F) -> &mut Command where F: FnMut() -> Result<()> + Send + Sync + 'static;
        fn exec(&mut self) -> Error;
    }

Unix-specific extensions to the `std::process::Command` builder

## Required Methods

### `fn uid(&mut self, id: u32) -> &mut Command`

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.

### `fn gid(&mut self, id: u32) -> &mut Command`

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

### `fn before_exec<F>(&mut self, f: F) -> &mut Command where F: FnMut() -> Result<()> + Send + Sync + 'static`
1.15.0

Schedules a closure to be run just before the `exec` function is invoked.

The closure is allowed to return an I/O error whose OS error code will be communicated back to the parent and returned as an error from when the spawn was requested.

Multiple closures can be registered and they will be called in order of their registration. If a closure returns `Err` then no further closures will be called and the spawn operation will immediately return with a failure.

# Notes

This closure will be run in the context of the child process after a `fork`. This primarily means that any modificatons made to memory on behalf of this closure will not be visible to the parent process. This is often a very constrained environment where normal operations like `malloc` or acquiring a mutex are not guaranteed to work (due to other threads perhaps still running when the `fork` was run).

When this closure is run, aspects such as the stdio file descriptors and working directory have successfully been changed, so output to these locations may not appear where intended.

### `fn exec(&mut self) -> Error`
1.9.0

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.

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.

## Implementors

- `impl CommandExt for Command`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)