Expand description
Production-grade subprocess runner with typed errors, retry, and timeout.
procpilot provides one entry point — the Cmd builder — covering every
practical subprocess configuration. Errors are typed: RunError
distinguishes spawn failure, non-zero exit, and timeout, each carrying
the last 128 KiB of stdout/stderr for diagnosis.
§Quick start
use std::time::Duration;
use procpilot::{Cmd, RunError};
let output = Cmd::new("git")
.args(["show", "maybe-missing-ref"])
.timeout(Duration::from_secs(30))
.run();
match output {
Ok(o) => println!("{}", o.stdout_lossy()),
Err(RunError::NonZeroExit { .. }) => { /* ref not found */ }
Err(e) => return Err(e.into()),
}§Features
- Typed errors:
RunErrorvariants for spawn / non-zero / timeout, with shell-quoted command display (secret-redacted viaCmd::secret). - Stdin:
Cmd::stdinaccepts owned bytes (reusable across retries) or a boxedRead(one-shot). - Stderr routing:
Redirectioncovers capture, inherit, null, and file redirection. - Timeout + deadline:
Cmd::timeoutfor per-attempt,Cmd::deadlinefor overall wall-clock budget across retries. - Retry with exponential backoff:
Cmd::retry/Cmd::retry_when. - Escape hatches:
Cmd::before_spawnfor pre-spawn hooks,Cmd::to_commandto drop to rawstd::process::Command.
Release history: CHANGELOG.md.
Structs§
- Cmd
- Builder for a subprocess invocation or pipeline.
- CmdDisplay
- Owned snapshot of a command’s program + args, formatted shell-style on
Display. For pipelines, renders each stage separated by|. - Retry
Policy - How retries are scheduled and which errors trigger them.
- RunOutput
- Captured output from a successful command.
- Spawned
Process - Handle to a spawned subprocess.
Enums§
- Redirection
- Where a child process’s stderr (or stdout, when supported) goes.
- RunError
- Error type for subprocess execution.
- Stdin
Data - Input data to feed to a child process’s stdin.
Constants§
- STREAM_
SUFFIX_ SIZE - Maximum bytes of stdout/stderr retained on
NonZeroExitandTimeouterror variants. Anything beyond this is dropped from the front (FIFO), keeping the most recent output — usually the most relevant for debugging.
Functions§
- binary_
available - Check whether a binary is available on PATH.
- binary_
version - Return a binary’s
--versionoutput, if available. - default_
transient - Default transient-error predicate.
Type Aliases§
- Before
Spawn Hook - Hook invoked on
std::process::Commandimmediately before each spawn attempt.