Skip to content

Commit

Permalink
xtask: Add util::get_cmd_stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasbishop committed Nov 11, 2023
1 parent ce75b75 commit 544ce0c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions xtask/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ pub fn run_cmd(mut cmd: Command) -> Result<()> {
}
}

/// Print a `Command` and run it, then check that it completes
/// successfully. Return the command's stdout.
pub fn get_cmd_stdout(mut cmd: Command) -> Result<Vec<u8>> {
println!("run_cmd: '{}'", command_to_string(&cmd));

let output = cmd.output()?;
if output.status.success() {
Ok(output.stdout)
} else {
bail!("command failed: {}", output.status);
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 544ce0c

Please sign in to comment.