BackgroundProcess

Struct BackgroundProcess 

Source
pub struct BackgroundProcess { /* private fields */ }
Expand description

A background process handle.

Implementations§

Source§

impl BackgroundProcess

Source

pub fn spawn(command: Command) -> Result<Self>

Spawn a new background process.

Source

pub fn spawn_piped(command: Command) -> Result<Self>

Spawn a new background process with piped stdout and stderr.

This allows reading the process output while it’s running.

§Example
let mut cmd = Command::new("agtrace");
cmd.args(&["watch"]);

let mut proc = BackgroundProcess::spawn_piped(cmd).unwrap();

// Read output
if let Some(stdout) = proc.stdout() {
    let reader = BufReader::new(stdout);
    for line in reader.lines() {
        println!("Output: {:?}", line);
    }
}
Source

pub fn wait_timeout(&mut self, timeout: Duration) -> Result<Option<ExitStatus>>

Wait for the process to exit with a timeout.

Source

pub fn kill(&mut self) -> Result<()>

Kill the process.

Source

pub fn id(&self) -> u32

Get the process ID.

Source

pub fn stdout(&mut self) -> Option<&mut ChildStdout>

Get mutable access to the process’s stdout.

Returns None if stdout was not captured (process must be spawned with spawn_piped).

§Example
let mut cmd = Command::new("agtrace");
let mut proc = BackgroundProcess::spawn_piped(cmd).unwrap();

if let Some(stdout) = proc.stdout() {
    let reader = BufReader::new(stdout);
    for line in reader.lines().take(5) {
        println!("{:?}", line);
    }
}
Source

pub fn stderr(&mut self) -> Option<&mut ChildStderr>

Get mutable access to the process’s stderr.

Returns None if stderr was not captured (process must be spawned with spawn_piped).

Trait Implementations§

Source§

impl Drop for BackgroundProcess

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.