Skip to content

Commit 800e7e1

Browse files
authored
Merge pull request #1778 from HosseinAssaran/patch-2
Update the example in pipe.md to make it compatible with both Windows OS and Unix-type systems
2 parents 933c339 + c75e245 commit 800e7e1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/std_misc/process/pipe.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@ process via pipes.
66

77
```rust,ignore
88
use std::io::prelude::*;
9-
use std::process::{Command, Stdio};
9+
use std::process::Stdio;
1010
1111
static PANGRAM: &'static str =
1212
"the quick brown fox jumped over the lazy dog\n";
1313
1414
fn main() {
1515
// Spawn the `wc` command
16-
let process = match Command::new("wc")
16+
#[cfg(target_family = "unix")]
17+
mod platform {
18+
use std::process::Command;
19+
pub fn wc() -> Box<Command> {
20+
let process = Command::new("wc");
21+
Box::new(process)
22+
}
23+
}
24+
#[cfg(target_family = "windows")]
25+
mod platform {
26+
use std::process::Command;
27+
pub fn wc() -> Box<Command> {
28+
let mut process = Command::new("powershell");
29+
process.arg("-Command").arg("$input | Measure-Object -Line -Word -Character");
30+
Box::new(process)
31+
}
32+
}
33+
34+
let process = match platform::wc()
1735
.stdin(Stdio::piped())
1836
.stdout(Stdio::piped())
1937
.spawn() {

0 commit comments

Comments
 (0)