pub struct CommandBuilder { /* private fields */ }Expand description
Command builder for synchronous execution.
Implementations§
Source§impl CommandBuilder
impl CommandBuilder
Sourcepub fn new<S: AsRef<OsStr>>(program: S) -> Self
pub fn new<S: AsRef<OsStr>>(program: S) -> Self
Creates a new command builder for the specified program.
Sourcepub fn envs<I, K, V>(self, vars: I) -> Self
pub fn envs<I, K, V>(self, vars: I) -> Self
Sets multiple environment variables for the command.
Sourcepub fn env_clear(self) -> Self
pub fn env_clear(self) -> Self
Clears all environment variables inherited from the parent process.
Sourcepub fn env_remove<K>(self, key: K) -> Self
pub fn env_remove<K>(self, key: K) -> Self
Removes an environment variable from the command’s environment.
Sourcepub fn current_dir<D>(self, dir: D) -> Self
pub fn current_dir<D>(self, dir: D) -> Self
Sets the working directory for the command.
Sourcepub fn stdin<T: Into<Stdio>>(self, stdin: T) -> Self
pub fn stdin<T: Into<Stdio>>(self, stdin: T) -> Self
Configures the stdin handle for the command.
Sourcepub fn stdout<T: Into<Stdio>>(self, stdout: T) -> Self
pub fn stdout<T: Into<Stdio>>(self, stdout: T) -> Self
Configures the stdout handle for the command.
Sourcepub fn stderr<T: Into<Stdio>>(self, stderr: T) -> Self
pub fn stderr<T: Into<Stdio>>(self, stderr: T) -> Self
Configures the stderr handle for the command.
Sourcepub fn capture_output(self) -> Self
pub fn capture_output(self) -> Self
Configures the command to capture both stdout and stderr.
Sourcepub fn inherit_stdin(self) -> Self
pub fn inherit_stdin(self) -> Self
Configures the command to inherit stdin from the parent process.
Sourcepub fn inherit_stdout(self) -> Self
pub fn inherit_stdout(self) -> Self
Configures the command to inherit stdout from the parent process.
Sourcepub fn inherit_stderr(self) -> Self
pub fn inherit_stderr(self) -> Self
Configures the command to inherit stderr from the parent process.
Sourcepub fn null_stdin(self) -> Self
pub fn null_stdin(self) -> Self
Configures the command to read from null stdin.
Sourcepub fn null_stdout(self) -> Self
pub fn null_stdout(self) -> Self
Configures the command to write to null stdout.
Sourcepub fn null_stderr(self) -> Self
pub fn null_stderr(self) -> Self
Configures the command to write to null stderr.
Sourcepub fn process_group(self, pgroup: i32) -> Self
pub fn process_group(self, pgroup: i32) -> Self
Sets the process group ID of the child process.
A pgroup of 0 will cause the child to be placed in a new process group.
§Errors
Returns an error if the process group could not be set.
Sourcepub fn setsid(self, create: bool) -> Self
pub fn setsid(self, create: bool) -> Self
Sets whether the child process should create a new session.
If create is true, the child process will call setsid to create
a new session and become the session leader.
§Errors
Returns an error if setsid fails.
Sourcepub fn uid(self, id: u32) -> Self
pub fn uid(self, id: u32) -> 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.
§Errors
Returns an error if the UID could not be set.
Sourcepub fn gid(self, id: u32) -> Self
pub fn gid(self, id: u32) -> Self
Sets the child process’s group ID.
This translates to a setgid call in the child process.
Failure in the setgid call will cause the spawn to fail.
§Errors
Returns an error if the GID could not be set.
Sourcepub fn creation_flags(self, _flags: u32) -> Self
pub fn creation_flags(self, _flags: u32) -> Self
Sets platform-specific creation flags (no-op on non-Windows).
Note: On Unix, use process_group, setsid, uid, or gid instead.
Sourcepub fn execute(&mut self) -> ScriptResult<Output>
pub fn execute(&mut self) -> ScriptResult<Output>
Executes the command and captures its output, returning a ScriptResult.
Sourcepub fn status(&mut self) -> Result<ExitStatus>
pub fn status(&mut self) -> Result<ExitStatus>
Waits for the command to complete and returns its exit status.
Sourcepub fn execute_with_timeout(self, timeout: Duration) -> ScriptResult<Output>
pub fn execute_with_timeout(self, timeout: Duration) -> ScriptResult<Output>
Executes the command with a timeout.
If the command does not complete within the specified duration, the child process is killed and a timeout error is returned.
Note: The builder is consumed by this operation and cannot be reused.
§Errors
Returns ScriptError::Timeout if the command exceeds the timeout.
Returns ScriptError::IoError if the command fails to start or execute.