Skip to main content

run_with_timeout

Function run_with_timeout 

Source
pub fn run_with_timeout(cmd: Command, timeout: Duration) -> Option<Output>
Expand description

Run a command with a hard timeout, capturing its output.

Returns Some(output) if the child exits within timeout, or None if it had to be killed (timed out) or could not be spawned. This is the safe way to invoke external control tools (launchctl, systemctl, a freshly installed binary’s --version, …) that must never be able to hang a lean-ctx command — a wedged launchctl previously forced users to reboot.

Note: intended for commands with small output. The child’s stdout/stderr are piped; a process that writes more than the pipe buffer (~64 KiB) without exiting could block. All current callers emit at most a few lines.