Skip to content

Commit 70e0f0a

Browse files
authored
Merge pull request #1780 from HosseinAssaran/patch-3
Make example in pipe.md compatible with both Windows and Unix-type system with less code
2 parents 32f5fa0 + f3b5eb9 commit 70e0f0a

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/std_misc/process/pipe.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,14 @@ static PANGRAM: &'static str =
1313
1414
fn main() {
1515
// Spawn the `wc` command
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()
16+
let mut cmd = if cfg!(target_family = "windows") {
17+
let mut cmd = Command::new("powershell");
18+
cmd.arg("-Command").arg("$input | Measure-Object -Line -Word -Character");
19+
cmd
20+
} else {
21+
Command::new("wc")
22+
};
23+
let process = match cmd
3524
.stdin(Stdio::piped())
3625
.stdout(Stdio::piped())
3726
.spawn() {

0 commit comments

Comments
 (0)