diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-02-12 10:28:03 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-03-08 17:45:44 -0800 |
| commit | 6afa32a2504fa90b48f74979bb4061cb397e9270 (patch) | |
| tree | b325bcb62312baba1cf50bc5806f9f9ab505c76b /src/libstd/process.rs | |
| parent | d46c99abe8671479c48b003bf06e98eda7eb85ab (diff) | |
| download | rust-6afa32a2504fa90b48f74979bb4061cb397e9270.tar.gz rust-6afa32a2504fa90b48f74979bb4061cb397e9270.zip | |
std: Don't always create stdin for children
For example if `Command::output` or `Command::status` is used then stdin is just immediately closed. Add an option for this so as an optimization we can avoid creating pipes entirely. This should help reduce the number of active file descriptors when spawning processes on Unix and the number of active handles on Windows.
Diffstat (limited to 'src/libstd/process.rs')
| -rw-r--r-- | src/libstd/process.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs index ec86dd062b5..fe5e49ecb09 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -295,7 +295,7 @@ impl Command { /// By default, stdin, stdout and stderr are inherited from the parent. #[stable(feature = "process", since = "1.0.0")] pub fn spawn(&mut self) -> io::Result<Child> { - self.inner.spawn(imp::Stdio::Inherit).map(Child::from_inner) + self.inner.spawn(imp::Stdio::Inherit, true).map(Child::from_inner) } /// Executes the command as a child process, waiting for it to finish and @@ -318,7 +318,7 @@ impl Command { /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn output(&mut self) -> io::Result<Output> { - self.inner.spawn(imp::Stdio::MakePipe).map(Child::from_inner) + self.inner.spawn(imp::Stdio::MakePipe, false).map(Child::from_inner) .and_then(|p| p.wait_with_output()) } @@ -340,7 +340,8 @@ impl Command { /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn status(&mut self) -> io::Result<ExitStatus> { - self.spawn().and_then(|mut p| p.wait()) + self.inner.spawn(imp::Stdio::Inherit, false).map(Child::from_inner) + .and_then(|mut p| p.wait()) } } |
