Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the example in pipe.md to make it compatible with both Windows OS and Unix-type systems #1778

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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