Skip to content

Commit 1abf43b

Browse files
authored
Rollup merge of rust-lang#99214 - beyarkay:patch-1, r=thomcc
docs: show how to stringify the output of Command This documentation-only change clarifies how the user can get the string representation of the output of a command. The `stdout` and `stderr` members of `std::process::Output` from `std::process::Command` return a Vec<u8>, which is not always what the user wants. For simple cases like printing `stderr` iff the `std::process::ExitStatus` is non-zero, it's useful to get the string representation of this `Vec<u8>`. This can be done via `String::from_utf8_lossy`, but it's not clear that this is possible from the documentation without first searching the internet for an answer. Link to playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8189f65dc4b354a643311af2cea5b230
2 parents ed91732 + 988a7e7 commit 1abf43b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/std/src/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl fmt::Debug for ChildStderr {
474474
/// .expect("failed to execute process")
475475
/// };
476476
///
477-
/// let hello = output.stdout;
477+
/// assert_eq!(String::from_utf8_lossy(&output.stdout), "hello\n");
478478
/// ```
479479
///
480480
/// `Command` can be reused to spawn multiple processes. The builder methods

0 commit comments

Comments
 (0)