1
Fork 0

Avoid converting bytes to UTF-8 strings to print, just pass bytes to stdout/err

This commit is contained in:
Santiago Pastorino 2018-11-10 14:16:04 -03:00
parent 12a88a6b09
commit 3b3b60ce6e
No known key found for this signature in database
GPG key ID: 88C941CDA1D46432

View file

@ -764,14 +764,15 @@ impl Command {
/// ///
/// ```should_panic /// ```should_panic
/// use std::process::Command; /// use std::process::Command;
/// use std::io::{self, Write};
/// let output = Command::new("/bin/cat") /// let output = Command::new("/bin/cat")
/// .arg("file.txt") /// .arg("file.txt")
/// .output() /// .output()
/// .expect("failed to execute process"); /// .expect("failed to execute process");
/// ///
/// println!("status: {}", output.status); /// println!("status: {}", output.status);
/// println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); /// io::stdout().write_all(&output.stdout).unwrap();
/// println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); /// io::stderr().write_all(&output.stderr).unwrap();
/// ///
/// assert!(output.status.success()); /// assert!(output.status.success());
/// ``` /// ```
@ -951,6 +952,7 @@ impl Stdio {
/// ///
/// ```no_run /// ```no_run
/// use std::process::{Command, Stdio}; /// use std::process::{Command, Stdio};
/// use std::io::{self, Write};
/// ///
/// let output = Command::new("rev") /// let output = Command::new("rev")
/// .stdin(Stdio::inherit()) /// .stdin(Stdio::inherit())
@ -958,7 +960,8 @@ impl Stdio {
/// .output() /// .output()
/// .expect("Failed to execute command"); /// .expect("Failed to execute command");
/// ///
/// println!("You piped in the reverse of: {}", String::from_utf8_lossy(&output.stdout)); /// print!("You piped in the reverse of: ");
/// io::stdout().write_all(&output.stdout).unwrap();
/// ``` /// ```
#[stable(feature = "process", since = "1.0.0")] #[stable(feature = "process", since = "1.0.0")]
pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) }