Run a command inheriting stdio; error if it fails.
(cmd: impl AsRef<OsStr>, args: &[&str], cwd: Option<&Path>)
| 9 | |
| 10 | /// Run a command inheriting stdio; error if it fails. |
| 11 | fn run_inherit(cmd: impl AsRef<OsStr>, args: &[&str], cwd: Option<&Path>) -> Result<()> { |
| 12 | let cmd = cmd.as_ref(); |
| 13 | let mut c = Command::new(cmd); |
| 14 | if let Some(cwd) = cwd { |
| 15 | c.current_dir(cwd); |
| 16 | } |
| 17 | let status = c |
| 18 | .args(args) |
| 19 | .stdin(Stdio::null()) |
| 20 | .status() |
| 21 | .with_context(|| format!("Failed to start {cmd:?}"))?; |
| 22 | if !status.success() { |
| 23 | return Err(anyhow!("Command failed: {cmd:?} {args:?} (exit {status})")); |
| 24 | } |
| 25 | Ok(()) |
| 26 | } |
| 27 | |
| 28 | /// Run a command and return captured stdout as UTF-8 string. |
| 29 | fn run_capture(cmd: &str, args: &[&str]) -> Result<String> { |