Skip to content

Commit 1449acc

Browse files
authored
Rollup merge of rust-lang#55754 - spastorino:fix-process-output-docs, r=alexcrichton
Avoid converting bytes to UTF-8 strings to print, just pass bytes to stdout/err r? @nikomatsakis
2 parents d1af662 + 3b3b60c commit 1449acc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/libstd/process.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,14 +764,15 @@ impl Command {
764764
///
765765
/// ```should_panic
766766
/// use std::process::Command;
767+
/// use std::io::{self, Write};
767768
/// let output = Command::new("/bin/cat")
768769
/// .arg("file.txt")
769770
/// .output()
770771
/// .expect("failed to execute process");
771772
///
772773
/// println!("status: {}", output.status);
773-
/// println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
774-
/// println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
774+
/// io::stdout().write_all(&output.stdout).unwrap();
775+
/// io::stderr().write_all(&output.stderr).unwrap();
775776
///
776777
/// assert!(output.status.success());
777778
/// ```
@@ -951,14 +952,16 @@ impl Stdio {
951952
///
952953
/// ```no_run
953954
/// use std::process::{Command, Stdio};
955+
/// use std::io::{self, Write};
954956
///
955957
/// let output = Command::new("rev")
956958
/// .stdin(Stdio::inherit())
957959
/// .stdout(Stdio::piped())
958960
/// .output()
959961
/// .expect("Failed to execute command");
960962
///
961-
/// println!("You piped in the reverse of: {}", String::from_utf8_lossy(&output.stdout));
963+
/// print!("You piped in the reverse of: ");
964+
/// io::stdout().write_all(&output.stdout).unwrap();
962965
/// ```
963966
#[stable(feature = "process", since = "1.0.0")]
964967
pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) }

0 commit comments

Comments
 (0)