2 // ignore-cross-compile
7 use std::io::{Read, Write};
8 use std::process::{Command, Stdio};
9 use std::path::PathBuf;
12 if env::args().len() > 1 {
19 fn parent() -> io::Result<()> {
20 let td = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
21 let input = td.join("stdio-from-input");
22 let output = td.join("stdio-from-output");
24 File::create(&input)?.write_all(b"foo\n")?;
27 // $ me <file | me | me >file
28 // ... to duplicate each line 8 times total.
30 let mut child1 = Command::new(env::current_exe()?)
32 .stdin(File::open(&input)?) // tests File::into()
33 .stdout(Stdio::piped())
36 let mut child3 = Command::new(env::current_exe()?)
38 .stdin(Stdio::piped())
39 .stdout(File::create(&output)?) // tests File::into()
42 // Started out of order so we can test both `ChildStdin` and `ChildStdout`.
43 let mut child2 = Command::new(env::current_exe()?)
45 .stdin(child1.stdout.take().unwrap()) // tests ChildStdout::into()
46 .stdout(child3.stdin.take().unwrap()) // tests ChildStdin::into()
49 assert!(child1.wait()?.success());
50 assert!(child2.wait()?.success());
51 assert!(child3.wait()?.success());
53 let mut data = String::new();
54 File::open(&output)?.read_to_string(&mut data)?;
55 for line in data.lines() {
56 assert_eq!(line, "foo");
58 assert_eq!(data.lines().count(), 8);
62 fn child() -> io::Result<()> {
64 let mut input = vec![];
65 io::stdin().read_to_end(&mut input)?;
66 io::stdout().write_all(&input)?;
67 io::stdout().write_all(&input)?;