Skip to content

Commit

Permalink
Merge pull request #1780 from HosseinAssaran/patch-3
Browse files Browse the repository at this point in the history
Make example in pipe.md compatible with both Windows and Unix-type system with less code
  • Loading branch information
marioidival authored Dec 14, 2023
2 parents 32f5fa0 + f3b5eb9 commit 70e0f0a
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/std_misc/process/pipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,14 @@ static PANGRAM: &'static str =
fn main() {
// Spawn the `wc` command
#[cfg(target_family = "unix")]
mod platform {
use std::process::Command;
pub fn wc() -> Box<Command> {
let process = Command::new("wc");
Box::new(process)
}
}
#[cfg(target_family = "windows")]
mod platform {
use std::process::Command;
pub fn wc() -> Box<Command> {
let mut process = Command::new("powershell");
process.arg("-Command").arg("$input | Measure-Object -Line -Word -Character");
Box::new(process)
}
}
let process = match platform::wc()
let mut cmd = if cfg!(target_family = "windows") {
let mut cmd = Command::new("powershell");
cmd.arg("-Command").arg("$input | Measure-Object -Line -Word -Character");
cmd
} else {
Command::new("wc")
};
let process = match cmd
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn() {
Expand Down

0 comments on commit 70e0f0a

Please sign in to comment.