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
13 #![feature(rustc_private)]
20 use std::io::{Read, Write};
21 use std::process::{Command, Stdio};
26 if env::args().len() > 1 {
33 fn parent() -> io::Result<()> {
34 let td = TempDir::new("foo").unwrap();
35 let input = td.path().join("input");
36 let output = td.path().join("output");
38 File::create(&input)?.write_all(b"foo\n")?;
41 // $ me <file | me | me >file
42 // ... to duplicate each line 8 times total.
44 let mut child1 = Command::new(env::current_exe()?)
46 .stdin(File::open(&input)?) // tests File::into()
47 .stdout(Stdio::piped())
50 let mut child3 = Command::new(env::current_exe()?)
52 .stdin(Stdio::piped())
53 .stdout(File::create(&output)?) // tests File::into()
56 // Started out of order so we can test both `ChildStdin` and `ChildStdout`.
57 let mut child2 = Command::new(env::current_exe()?)
59 .stdin(child1.stdout.take().unwrap()) // tests ChildStdout::into()
60 .stdout(child3.stdin.take().unwrap()) // tests ChildStdin::into()
63 assert!(child1.wait()?.success());
64 assert!(child2.wait()?.success());
65 assert!(child3.wait()?.success());
67 let mut data = String::new();
68 File::open(&output)?.read_to_string(&mut data)?;
69 for line in data.lines() {
70 assert_eq!(line, "foo");
72 assert_eq!(data.lines().count(), 8);
76 fn child() -> io::Result<()> {
78 let mut input = vec![];
79 io::stdin().read_to_end(&mut input)?;
80 io::stdout().write_all(&input)?;
81 io::stdout().write_all(&input)?;