File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 1
- use anyhow:: { bail, Result } ;
1
+ use anyhow:: { bail, Context , Result } ;
2
2
use std:: process:: Command ;
3
3
4
4
/// Format a `Command` as a `String.
@@ -44,6 +44,19 @@ pub fn run_cmd(mut cmd: Command) -> Result<()> {
44
44
}
45
45
}
46
46
47
+ /// Print a `Command` and run it, then check that it completes
48
+ /// successfully. Return the command's stdout as a `String`.
49
+ pub fn run_cmd_get_stdout ( mut cmd : Command ) -> Result < String > {
50
+ println ! ( "run_cmd: '{}'" , command_to_string( & cmd) ) ;
51
+
52
+ let output = cmd. output ( ) ?;
53
+ if output. status . success ( ) {
54
+ String :: from_utf8 ( output. stdout ) . context ( "command output is not utf-8" )
55
+ } else {
56
+ bail ! ( "command failed: {}" , output. status) ;
57
+ }
58
+ }
59
+
47
60
#[ cfg( test) ]
48
61
mod tests {
49
62
use super :: * ;
You can’t perform that action at this time.
0 commit comments