Skip to content

Commit f12c118

Browse files
xtask: Add get_cmd_stdout
1 parent 0bbbaf6 commit f12c118

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

xtask/src/util.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@
99
use anyhow::{bail, Result};
1010
use std::process::Command;
1111

12-
pub fn run_cmd(mut cmd: Command) -> Result<()> {
12+
fn print_cmd(cmd: &Command) {
1313
println!("Running: {}", format!("{cmd:?}").replace('"', ""));
14+
}
15+
16+
pub fn run_cmd(mut cmd: Command) -> Result<()> {
17+
print_cmd(&cmd);
1418
let status = cmd.status().expect("failed to launch");
1519
if status.success() {
1620
Ok(())
1721
} else {
1822
bail!("command failed: {status}");
1923
}
2024
}
25+
26+
pub fn get_cmd_stdout(mut cmd: Command) -> Result<Vec<u8>> {
27+
print_cmd(&cmd);
28+
let output = cmd.output().expect("failed to launch");
29+
if output.status.success() {
30+
Ok(output.stdout)
31+
} else {
32+
bail!("command failed: {}", output.status);
33+
}
34+
}

0 commit comments

Comments
 (0)