Skip to content

Commit 7074902

Browse files
xtask: Add util::get_cmd_stdout
1 parent 77e9841 commit 7074902

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

xtask/src/util.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ pub fn run_cmd(mut cmd: Command) -> Result<()> {
4444
}
4545
}
4646

47+
/// Print a `Command` and run it, then check that it completes
48+
/// successfully. Return the command's stdout.
49+
pub fn get_cmd_stdout(mut cmd: Command) -> Result<Vec<u8>> {
50+
println!("run_cmd: '{}'", command_to_string(&cmd));
51+
52+
let output = cmd.output()?;
53+
if output.status.success() {
54+
Ok(output.stdout)
55+
} else {
56+
bail!("command failed: {}", output.status);
57+
}
58+
}
59+
4760
#[cfg(test)]
4861
mod tests {
4962
use super::*;

0 commit comments

Comments
 (0)