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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use failure::Error;
use install::Tool;
use log::info;
use std::process::{Command, Stdio};
pub fn new_command(program: &str) -> Command {
if cfg!(windows) {
let mut cmd = Command::new("cmd");
cmd.arg("/c").arg(program);
cmd
} else {
Command::new(program)
}
}
pub fn run(mut command: Command, command_name: &str) -> Result<(), Error> {
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,
)
}
}
pub fn run_capture_stdout(mut command: Command, command_name: &Tool) -> Result<String, Error> {
info!("Running {:?}", command);
let output = command
.stderr(Stdio::inherit())
.stdin(Stdio::inherit())
.output()?;
if output.status.success() {
Ok(String::from_utf8_lossy(&output.stdout).into_owned())
} else {
bail!(
"failed to execute `{}`: exited with {}\n full command: {:?}",
command_name,
output.status,
command,
)
}
}