pub struct BackgroundProcess { /* private fields */ }Expand description
A background process handle.
Implementations§
Source§impl BackgroundProcess
impl BackgroundProcess
Sourcepub fn spawn_piped(command: Command) -> Result<Self>
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);
}
}Sourcepub fn wait_timeout(&mut self, timeout: Duration) -> Result<Option<ExitStatus>>
pub fn wait_timeout(&mut self, timeout: Duration) -> Result<Option<ExitStatus>>
Wait for the process to exit with a timeout.
Sourcepub fn stdout(&mut self) -> Option<&mut ChildStdout>
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);
}
}Sourcepub fn stderr(&mut self) -> Option<&mut ChildStderr>
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§
Auto Trait Implementations§
impl Freeze for BackgroundProcess
impl RefUnwindSafe for BackgroundProcess
impl Send for BackgroundProcess
impl Sync for BackgroundProcess
impl Unpin for BackgroundProcess
impl UnwindSafe for BackgroundProcess
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more