1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::process::{Command, Stdio};
use log::info;
use anyhow::{bail, Result};
/// Return a new Command object
pub fn new_command(program: &str) -> Command {
// On Windows, initializes launching <program> as `cmd /c <program>`.
// Initializing only with `Command::new("npm")` will launch
// `npm` with quotes, `"npm"`, causing a run-time error on Windows.
// See rustc: #42436, #42791, #44542
if cfg!(windows) {
let mut cmd = Command::new("cmd");
cmd.arg("/c").arg(program);
cmd
} else {
Command::new(program)
}
}
/// Run the given command and return on success.
pub fn run(mut command: Command, command_name: &str) -> Result<()> {
info!("Running {:?}", command);
let status = command.status()?;
if status.success() {
Ok(())
} else {
bail!(
"failed to execute `{}`: exited with {}\n full command: {:?}",
command_name,
status,
command,
)
}
}