Initial implementation of anonymous_pipe
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com> Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
52f3c71c8d
commit
c9c8a14884
17 changed files with 551 additions and 16 deletions
39
library/std/tests/pipe_subprocess.rs
Normal file
39
library/std/tests/pipe_subprocess.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
#![feature(anonymous_pipe)]
|
||||
|
||||
fn main() {
|
||||
#[cfg(all(not(miri), any(unix, windows)))]
|
||||
{
|
||||
use std::{env, io::Read, pipe::pipe, 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,");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue