From c75e2455c9f4345d6c14d54a52d6afb3e497699a Mon Sep 17 00:00:00 2001 From: Hosssein Date: Sun, 10 Dec 2023 16:42:23 +0330 Subject: [PATCH] Update the example in pipe.md to make it compatible with both Windows OS and Unix-type systems --- src/std_misc/process/pipe.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/std_misc/process/pipe.md b/src/std_misc/process/pipe.md index fb0be0ea11..1692dd27c0 100644 --- a/src/std_misc/process/pipe.md +++ b/src/std_misc/process/pipe.md @@ -6,14 +6,32 @@ process via pipes. ```rust,ignore use std::io::prelude::*; -use std::process::{Command, Stdio}; +use std::process::Stdio; static PANGRAM: &'static str = "the quick brown fox jumped over the lazy dog\n"; fn main() { // Spawn the `wc` command - let process = match Command::new("wc") + #[cfg(target_family = "unix")] + mod platform { + use std::process::Command; + pub fn wc() -> Box { + let process = Command::new("wc"); + Box::new(process) + } + } + #[cfg(target_family = "windows")] + mod platform { + use std::process::Command; + pub fn wc() -> Box { + let mut process = Command::new("powershell"); + process.arg("-Command").arg("$input | Measure-Object -Line -Word -Character"); + Box::new(process) + } + } + + let process = match platform::wc() .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn() {