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 creation_flags(self, flags: u32) -> Self
pub fn creation_flags(self, flags: u32) -> Self
Sets the process creation flags (Windows only).
Sets the process creation flags to be passed to CreateProcess.
These will always be ORed with CREATE_UNICODE_ENVIRONMENT.
§Errors
This method does not return errors directly, but the spawned process may fail if the flags are invalid.
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.