Skip to main content

run_capped

Function run_capped 

pub fn run_capped(
    command: Command,
    timeout: Option<Duration>,
    cap: usize,
) -> Result<CappedRun>
Expand description

Runs command to completion under an optional wall-clock timeout, capturing stdout and stderr.

This is the crate::exec::Subprocess executor’s own wait_capped machinery made public for a caller that spawns its own child processes rather than going through the executor. It drains both pipes on their own threads into cap-bounded buffers. On Unix it puts the child in its own process group, so if timeout elapses it kills the whole group (reaching a grandchild the child spawned), and cancellable readers bound the drain after exit or timeout. On other platforms, timeout cleanup kills only the direct child and joins the pipe readers; a descendant that inherited a pipe can keep that join waiting indefinitely, so timeout does not guarantee bounded return there.

The child’s stdio is overridden to captured pipes and, on Unix, its process group is set to itself regardless of ambient environment variables or how command was configured; everything else about command (program, args, env, working dir) is used as given. Pass cap = 0 to keep all output, or a byte bound (e.g. 64 KiB) to retain only the most recent bytes of each stream.

§Errors

std::io::Error only for a genuine spawn or wait failure; a non-zero exit or a fatal signal is reported through CappedRun::Exited’s status, not as an error, and a timeout is CappedRun::TimedOut, not an error.