blob: 4be95afa4547fad4f1670e1f6dafa4cea988f944 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use std::io::Write;
use std::process::{Command, Stdio};
// Example of piping-in a string defined in Rust to a shell command.
pub fn example() {
let input = "Hello, world!";
let mut cat = Command::new("cat")
.stdin(Stdio::piped())
.spawn()
.ok()
.unwrap();
cat.stdin
.take()
.unwrap()
.write_all(&input.as_bytes())
.unwrap();
let output = cat.wait_with_output().unwrap();
println!("{}", String::from_utf8_lossy(&output.stdout));
}
|