[][src]Trait process_control::Terminator

pub trait Terminator: Sealed + Sized {
#[must_use]
    fn terminator(&self) -> ProcessTerminator;
fn wait_with_timeout(
        self,
        time_limit: Duration
    ) -> IoResult<Option<(ExitStatus, Self)>>;
fn wait_for_output_with_timeout(
        self,
        time_limit: Duration
    ) -> IoResult<Option<Output>>;
fn wait_with_terminating_timeout(
        self,
        time_limit: Duration
    ) -> IoResult<Option<(ExitStatus, Self)>>;
fn wait_for_output_with_terminating_timeout(
        self,
        time_limit: Duration
    ) -> IoResult<Option<Output>>; }

Extensions to Child for easily killing processes.

For more information, see the module-level documentation.

Required methods

#[must_use] fn terminator(&self) -> ProcessTerminator

Creates an instance of ProcessTerminator for this process.

Examples

use std::process::Command;

use process_control::Terminator;

let process = Command::new("echo").spawn()?;
let process_terminator = process.terminator();

fn wait_with_timeout(
    self,
    time_limit: Duration
) -> IoResult<Option<(ExitStatus, Self)>>

A convenience method for calling Child::wait with a timeout.

As the Child must be consumed by this method, it is returned if the process finishes. The instance would be required to subsequently access Child::stdout or other fields.

For more information, see wait_for_output_with_timeout.

fn wait_for_output_with_timeout(
    self,
    time_limit: Duration
) -> IoResult<Option<Output>>

A convenience method for calling Child::wait_with_output with a timeout.

If the time limit expires before that method finishes, Ok(None) will be returned. The process will not be terminated, so it may be desirable to call ProcessTerminator::terminate_if_necessary afterward to free system resources. wait_for_output_with_terminating_timeout can be used to call that method automatically.

This method will create a separate thread to run the method without blocking the current thread.

Examples

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

use process_control::Terminator;

let process = Command::new("echo").spawn()?;
let process_terminator = process.terminator();

let result =
    process.wait_for_output_with_timeout(Duration::from_secs(1))?;
process_terminator.terminate_if_necessary()?;

match result {
    Some(output) => assert!(output.status.success()),
    None => panic!("process timed out"),
}

fn wait_with_terminating_timeout(
    self,
    time_limit: Duration
) -> IoResult<Option<(ExitStatus, Self)>>

A convenience method for calling wait_with_timeout and terminating the process if it exceeds the time limit.

For more information, see wait_for_output_with_terminating_timeout.

fn wait_for_output_with_terminating_timeout(
    self,
    time_limit: Duration
) -> IoResult<Option<Output>>

A convenience method for calling wait_for_output_with_timeout and terminating the process if it exceeds the time limit.

Examples

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

use process_control::Terminator;

let process = Command::new("echo").spawn()?;
match process
    .wait_for_output_with_terminating_timeout(Duration::from_secs(1))?
{
    Some(output) => assert!(output.status.success()),
    None => panic!("process timed out"),
}
Loading content...

Implementations on Foreign Types

impl Terminator for Child[src]

Loading content...

Implementors

Loading content...