pub trait ChildExt<'a>: Sealed {
    type ExitStatusControl: 'a + Control<Result = ExitStatus> + Debug;
    type OutputControl: Control<Result = Output> + Debug;

    fn terminate_if_running(&mut self) -> Result<()>;
    fn controlled(&'a mut self) -> Self::ExitStatusControl;
    fn controlled_with_output(self) -> Self::OutputControl;
}
Expand description

Extensions to Child for easily terminating processes.

For more information, see the module-level documentation.

Required Associated Types§

The type returned by controlled.

The type returned by controlled_with_output.

Required Methods§

Equivalent to Child::kill but ignores errors when the process is no longer running.

Windows and Unix errors are inconsistent when terminating processes. This method unifies them by simulating Unix behavior on Windows.

Creates an instance of Control that yields ExitStatus for this process.

This method parallels Child::wait but allows setting limits on the process.

Examples
use std::process::Command;
use std::time::Duration;

use process_control::ChildExt;
use process_control::Control;

let exit_status = Command::new("echo")
    .spawn()?
    .controlled()
    .time_limit(Duration::from_secs(1))
    .terminate_for_timeout()
    .wait()?
    .expect("process timed out");
assert!(exit_status.success());

Creates an instance of Control that yields Output for this process.

This method parallels Child::wait_with_output but allows setting limits on the process.

Examples
use std::process::Command;
use std::time::Duration;

use process_control::ChildExt;
use process_control::Control;

let output = Command::new("echo")
    .spawn()?
    .controlled_with_output()
    .time_limit(Duration::from_secs(1))
    .terminate_for_timeout()
    .wait()?
    .expect("process timed out");
assert!(output.status.success());

Implementations on Foreign Types§

Implementors§