Skip to main content

CommandBuilder

Struct CommandBuilder 

Source
pub struct CommandBuilder { /* private fields */ }
Expand description

Command builder for synchronous execution.

Implementations§

Source§

impl CommandBuilder

Source

pub fn new<S: AsRef<OsStr>>(program: S) -> Self

Creates a new command builder for the specified program.

Source

pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self

Adds a single argument to the command.

Source

pub fn args<I, S>(self, args: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Adds multiple arguments to the command.

Source

pub fn env<K, V>(self, key: K, value: V) -> Self
where K: AsRef<OsStr>, V: AsRef<OsStr>,

Sets an environment variable for the command.

Source

pub fn envs<I, K, V>(self, vars: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

Sets multiple environment variables for the command.

Source

pub fn env_clear(self) -> Self

Clears all environment variables inherited from the parent process.

Source

pub fn env_remove<K>(self, key: K) -> Self
where K: AsRef<OsStr>,

Removes an environment variable from the command’s environment.

Source

pub fn current_dir<D>(self, dir: D) -> Self
where D: AsRef<Path>,

Sets the working directory for the command.

Source

pub fn stdin<T: Into<Stdio>>(self, stdin: T) -> Self

Configures the stdin handle for the command.

Source

pub fn stdout<T: Into<Stdio>>(self, stdout: T) -> Self

Configures the stdout handle for the command.

Source

pub fn stderr<T: Into<Stdio>>(self, stderr: T) -> Self

Configures the stderr handle for the command.

Source

pub fn capture_output(self) -> Self

Configures the command to capture both stdout and stderr.

Source

pub fn inherit_stdin(self) -> Self

Configures the command to inherit stdin from the parent process.

Source

pub fn inherit_stdout(self) -> Self

Configures the command to inherit stdout from the parent process.

Source

pub fn inherit_stderr(self) -> Self

Configures the command to inherit stderr from the parent process.

Source

pub fn null_stdin(self) -> Self

Configures the command to read from null stdin.

Source

pub fn null_stdout(self) -> Self

Configures the command to write to null stdout.

Source

pub fn null_stderr(self) -> Self

Configures the command to write to null stderr.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn spawn(&mut self) -> Result<Child>

Spawns the command as a child process.

Source

pub fn output(&mut self) -> Result<Output>

Executes the command and captures its output.

Source

pub fn execute(&mut self) -> ScriptResult<Output>

Executes the command and captures its output, returning a ScriptResult.

Source

pub fn status(&mut self) -> Result<ExitStatus>

Waits for the command to complete and returns its exit status.

Source

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.

Trait Implementations§

Source§

impl Debug for CommandBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.