@@ -1286,6 +1286,40 @@ pub struct Output {
1286
1286
pub stderr : Vec < u8 > ,
1287
1287
}
1288
1288
1289
+ impl Output {
1290
+ /// Returns an error if a nonzero exit status was received.
1291
+ ///
1292
+ /// If the [`Command`] exited successfully,
1293
+ /// `self` is returned.
1294
+ ///
1295
+ /// This is equivalent to calling [`exit_ok`](ExitStatus::exit_ok)
1296
+ /// on [`Output.status`](Output::status).
1297
+ ///
1298
+ /// Note that this will throw away the [`Output::stderr`] field in the error case.
1299
+ /// If the child process outputs useful informantion to stderr, you can:
1300
+ /// * Use `cmd.stderr(Stdio::inherit())` to forward the
1301
+ /// stderr child process to the parent's stderr,
1302
+ /// usually printing it to console where the user can see it.
1303
+ /// This is usually correct for command-line applications.
1304
+ /// * Capture `stderr` using a custom error type.
1305
+ /// This is usually correct for libraries.
1306
+ ///
1307
+ /// # Examples
1308
+ ///
1309
+ /// ```
1310
+ /// #![feature(exit_status_error)]
1311
+ /// # #[cfg(unix)] {
1312
+ /// use std::process::Command;
1313
+ /// assert!(Command::new("false").output().unwrap().exit_ok().is_err());
1314
+ /// # }
1315
+ /// ```
1316
+ #[ unstable( feature = "exit_status_error" , issue = "84908" ) ]
1317
+ pub fn exit_ok ( self ) -> Result < Self , ExitStatusError > {
1318
+ self . status . exit_ok ( ) ?;
1319
+ Ok ( self )
1320
+ }
1321
+ }
1322
+
1289
1323
// If either stderr or stdout are valid utf8 strings it prints the valid
1290
1324
// strings, otherwise it prints the byte sequence instead
1291
1325
#[ stable( feature = "process_output_debug" , since = "1.7.0" ) ]
0 commit comments