Skip to content

Commit

Permalink
Update the example in pipe.md to make it compatible with both Windows…
Browse files Browse the repository at this point in the history
… OS and Unix-type systems
  • Loading branch information
HosseinAssaran authored Dec 10, 2023
1 parent 933c339 commit c75e245
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/std_misc/process/pipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<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()
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn() {
Expand Down

0 comments on commit c75e245

Please sign in to comment.