diff --git a/library/std/src/process.rs b/library/std/src/process.rs index d91d4fa64caa5..21243593d3b81 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -461,20 +461,21 @@ impl fmt::Debug for ChildStderr { /// ``` /// use std::process::Command; /// -/// let output = if cfg!(target_os = "windows") { -/// Command::new("cmd") +/// if cfg!(target_os = "windows") { +/// let output = Command::new("cmd") /// .args(["/C", "echo hello"]) /// .output() -/// .expect("failed to execute process") +/// .expect("failed to execute process"); +/// assert_eq!(String::from_utf8_lossy(&output.stdout), "hello\r\n"); /// } else { -/// Command::new("sh") +/// let output = Command::new("sh") /// .arg("-c") /// .arg("echo hello") /// .output() -/// .expect("failed to execute process") +/// .expect("failed to execute process"); +/// assert_eq!(String::from_utf8_lossy(&output.stdout), "hello\n"); /// }; /// -/// let hello = output.stdout; /// ``` /// /// `Command` can be reused to spawn multiple processes. The builder methods