Sbprocess ((full)) -
sbprocess – A Minimal, Safe Wrapper Around Subprocesses (No Boilerplate)
[dependencies] sbprocess = "0.1.0" // Run and capture let out = cmd("git status --porcelain").run()?.stdout; // Run ignoring failure let _ = cmd("rm -f tmp.txt").run_ignored(); sbprocess
cargo add sbprocess
rust programming cli devtools subprocess The Problem We've all been there. You just need to run a shell command, capture its output, handle errors gracefully, and maybe pipe a few things together. But the standard library's std::process::Command quickly becomes verbose: sbprocess – A Minimal, Safe Wrapper Around Subprocesses
That’s a lot of .arg() calls, and error handling? You're on your own. You're on your own
// Capture both stdout and stderr separately let res = cmd("ls /nonexistent").run_unchecked(); println!("err: {}", res.stderr); use sbprocess::pipe; let result = pipe!("echo 'hello world'" | "wc -w").run().unwrap(); assert_eq!(result.stdout.trim(), "2"); With Timeout use sbprocess::cmd; use std::time::Duration; match cmd("sleep 10").timeout(Duration::from_secs(1)).run() { Ok(_) => println!("Finished"), Err(e) => println!("Timed out: {}", e), } Why Not Just Use std::process ? | Feature | std::process | sbprocess | |----------------------|--------------|------------| | String command | ❌ | ✅ | | Auto error messages | ❌ | ✅ | | Piping sugar | ❌ | ✅ | | Timeout | ❌ (manual) | ✅ | | Capture as String | ❌ (Vec ) | ✅ | Installation Add to your Cargo.toml :
