[][src]Crate process_control

This crate allows running a process with a timeout, with the option to terminate it automatically afterward. The latter is surprisingly difficult to achieve on Unix, since process identifiers can be arbitrarily reassigned when no longer used. Thus, it would be extremely easy to inadvertently terminate an unexpected process. This crate protects against that possibility.

Methods for creating timeouts are available on ChildExt, which is implemented for Child. They each return a builder of options to configure how the timeout should be applied.

Implementation

All traits are sealed, meaning that they can only be implemented by this crate. Otherwise, backward compatibility would be more difficult to maintain for new features.

Related Crates

Crate wait-timeout has a similar purpose, but it does not provide the same functionality. Processes cannot be terminated automatically, and there is no counterpart to Child::wait_with_output for simply reading output from a process with a timeout. This crate aims to fill in those gaps and simplify the implementation, now that Receiver::recv_timeout exists.

Examples

use std::io::Error as IoError;
use std::io::ErrorKind as IoErrorKind;
use std::process::Command;
use std::process::Stdio;
use std::time::Duration;

use process_control::ChildExt;

let process = Command::new("echo")
    .arg("hello")
    .stdout(Stdio::piped())
    .spawn()?;

let output = process
    .with_output_timeout(Duration::from_secs(1))
    .terminating()
    .wait()?
    .ok_or_else(|| {
        IoError::new(IoErrorKind::TimedOut, "Process timed out")
    })?;
assert_eq!(b"hello", &output.stdout[..5]);

Structs

ExitStatus

Equivalent to ExitStatus in the standard library but allows for greater accuracy.

Output

Equivalent to Output in the standard library but holds an instance of ExitStatus from this crate.

Terminator

A wrapper that stores enough information to terminate a process.

_ExitStatusTimeout

A temporary wrapper for a process timeout.

_OutputTimeout

A temporary wrapper for a process timeout.

Traits

ChildExt

Extensions to Child for easily terminating processes.