pub struct Command { /* private fields */ }Expand description
A description of a child process to launch: program, arguments, working directory, environment, stdin source, and an optional timeout.
A single builder for everything a run needs. Build it, then either drive it
to completion with a
helper (output_string, run, …) or
start it via a ProcessRunner for streaming/shared
groups.
Implementations§
Source§impl Command
impl Command
Sourcepub fn current_dir(self, dir: impl AsRef<Path>) -> Self
pub fn current_dir(self, dir: impl AsRef<Path>) -> Self
Set the working directory.
Sourcepub fn env(self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Self
pub fn env(self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Self
Set (or, with a None value, remove) an environment variable.
Sourcepub fn env_remove(self, key: impl AsRef<OsStr>) -> Self
pub fn env_remove(self, key: impl AsRef<OsStr>) -> Self
Remove an environment variable inherited from the parent.
Sourcepub fn env_clear(self) -> Self
pub fn env_clear(self) -> Self
Clear all inherited environment variables before applying any set here.
Sourcepub fn keep_stdin_open(self) -> Self
pub fn keep_stdin_open(self) -> Self
Leave stdin open after start so the child can be driven interactively via
RunningProcess::standard_input.
Has no effect on the bulk run helpers (they always close stdin).
Sourcepub fn on_stdout_line<F>(self, handler: F) -> Self
pub fn on_stdout_line<F>(self, handler: F) -> Self
Invoke handler for each decoded stdout line as it is read (in addition
to capture/streaming). Runs on the pump task; keep it cheap and panic-free.
Sourcepub fn on_stderr_line<F>(self, handler: F) -> Self
pub fn on_stderr_line<F>(self, handler: F) -> Self
Invoke handler for each decoded stderr line as it is read.
Sourcepub fn output_buffer(self, policy: OutputBufferPolicy) -> Self
pub fn output_buffer(self, policy: OutputBufferPolicy) -> Self
Cap the in-memory backlog of captured output lines (see
OutputBufferPolicy). The pump still drains the pipe; only retention is
bounded.
Sourcepub fn stdout_encoding(self, encoding: &'static Encoding) -> Self
pub fn stdout_encoding(self, encoding: &'static Encoding) -> Self
Decode stdout with encoding instead of UTF-8 (e.g.
encoding_rs::SHIFT_JIS).
Sourcepub fn stderr_encoding(self, encoding: &'static Encoding) -> Self
pub fn stderr_encoding(self, encoding: &'static Encoding) -> Self
Decode stderr with encoding instead of UTF-8.
Sourcepub fn encoding(self, encoding: &'static Encoding) -> Self
pub fn encoding(self, encoding: &'static Encoding) -> Self
Decode both stdout and stderr with encoding.
Sourcepub fn working_dir(&self) -> Option<&Path>
pub fn working_dir(&self) -> Option<&Path>
The working-directory override, if one was set.
Sourcepub fn env_overrides(&self) -> &[(OsString, Option<OsString>)]
pub fn env_overrides(&self) -> &[(OsString, Option<OsString>)]
The environment overrides, in order (a None value removes the variable).
Sourcepub fn stdin_source(&self) -> Option<&Stdin>
pub fn stdin_source(&self) -> Option<&Stdin>
The configured stdin source, if any.
Sourcepub fn configured_timeout(&self) -> Option<Duration>
pub fn configured_timeout(&self) -> Option<Duration>
The configured timeout, if any.
Sourcepub fn to_tokio_command(&self) -> Command
pub fn to_tokio_command(&self) -> Command
Build a tokio::process::Command with this command’s program, args,
working dir, and environment — stdio wired for capture. Use it to feed
the low-level ProcessGroup::spawn escape
hatch directly (which returns a raw tokio::process::Child).
Sourcepub async fn start(&self) -> Result<RunningProcess>
pub async fn start(&self) -> Result<RunningProcess>
Start the command and return a live RunningProcess backed by a fresh
private group. Use this for streaming stdout
(RunningProcess::stdout_lines) or inspecting the process while it
runs; keep the handle in scope, as dropping it tears the tree down.
Sourcepub async fn output_string(&self) -> Result<ProcessResult<String>>
pub async fn output_string(&self) -> Result<ProcessResult<String>>
Run to completion and capture stdout as text, stderr, and the exit code.
A non-zero exit is reported, not raised — call
ProcessResult::ensure_success to turn it into an error.
Sourcepub async fn output_bytes(&self) -> Result<ProcessResult<Vec<u8>>>
pub async fn output_bytes(&self) -> Result<ProcessResult<Vec<u8>>>
Run to completion and capture stdout as raw bytes (plus stderr/exit code).
Sourcepub async fn exit_code(&self) -> Result<i32>
pub async fn exit_code(&self) -> Result<i32>
Run to completion and return just the exit code (output is discarded). A
run that yields no code surfaces as an error — a timeout as
Error::Timeout, a signal-kill as an IO error —
consistent with
ProcessRunnerExt::exit_code and
CliClient::code.