forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpipe_subprocess.rs
38 lines (32 loc) · 942 Bytes
/
pipe_subprocess.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn main() {
#[cfg(all(not(miri), any(unix, windows), not(target_os = "emscripten")))]
{
use std::io::{Read, pipe};
use std::{env, process};
if env::var("I_AM_THE_CHILD").is_ok() {
child();
} else {
parent();
}
fn parent() {
let me = env::current_exe().unwrap();
let (rx, tx) = pipe().unwrap();
assert!(
process::Command::new(me)
.env("I_AM_THE_CHILD", "1")
.stdout(tx)
.status()
.unwrap()
.success()
);
let mut s = String::new();
(&rx).read_to_string(&mut s).unwrap();
drop(rx);
assert_eq!(s, "Heloo,\n");
println!("Test pipe_subprocess.rs success");
}
fn child() {
println!("Heloo,");
}
}
}