use std::time::Duration;
use procpilot::{Cmd, RunError};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let output = Cmd::new("echo").arg("hello from procpilot").run()?;
println!("stdout: {}", output.stdout_lossy().trim());
match Cmd::new("procpilot_example_missing_binary_xyz").run() {
Ok(_) => println!("unexpected: binary doesn't exist but succeeded?"),
Err(RunError::Spawn { source, .. }) => {
println!("couldn't spawn binary: {source}");
}
Err(other) => println!("other failure: {other}"),
}
match Cmd::new("sleep")
.arg("10")
.timeout(Duration::from_millis(100))
.run()
{
Ok(_) => println!("sleep finished unexpectedly"),
Err(RunError::Timeout { elapsed, .. }) => {
println!("killed sleep after {elapsed:?}");
}
Err(other) => println!("sleep failed: {other}"),
}
let out = Cmd::new("cat").stdin("piped input\n").run()?;
println!("echoed: {}", out.stdout_lossy().trim());
Ok(())
}