1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // ignore-cross-compile
16 use std::io::{Read, Write};
17 use std::process::{Command, Stdio};
18 use std::path::PathBuf;
21 if env::args().len() > 1 {
28 fn parent() -> io::Result<()> {
29 let td = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
30 let input = td.join("stdio-from-input");
31 let output = td.join("stdio-from-output");
33 File::create(&input)?.write_all(b"foo\n")?;
36 // $ me <file | me | me >file
37 // ... to duplicate each line 8 times total.
39 let mut child1 = Command::new(env::current_exe()?)
41 .stdin(File::open(&input)?) // tests File::into()
42 .stdout(Stdio::piped())
45 let mut child3 = Command::new(env::current_exe()?)
47 .stdin(Stdio::piped())
48 .stdout(File::create(&output)?) // tests File::into()
51 // Started out of order so we can test both `ChildStdin` and `ChildStdout`.
52 let mut child2 = Command::new(env::current_exe()?)
54 .stdin(child1.stdout.take().unwrap()) // tests ChildStdout::into()
55 .stdout(child3.stdin.take().unwrap()) // tests ChildStdin::into()
58 assert!(child1.wait()?.success());
59 assert!(child2.wait()?.success());
60 assert!(child3.wait()?.success());
62 let mut data = String::new();
63 File::open(&output)?.read_to_string(&mut data)?;
64 for line in data.lines() {
65 assert_eq!(line, "foo");
67 assert_eq!(data.lines().count(), 8);
71 fn child() -> io::Result<()> {
73 let mut input = vec![];
74 io::stdin().read_to_end(&mut input)?;
75 io::stdout().write_all(&input)?;
76 io::stdout().write_all(&input)?;