diff options
| author | bors <bors@rust-lang.org> | 2022-12-17 23:27:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-17 23:27:53 +0000 |
| commit | 24368ecdc4c0248d5ab14834576da96b9c2a9fa1 (patch) | |
| tree | d9098ad8ff8368e0096cee39bfff794fdbbeb397 /library/std/src/sys_common | |
| parent | 0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc (diff) | |
| parent | 8fc1a72e563582aa4f132f73b30cf049055a03c2 (diff) | |
| download | rust-24368ecdc4c0248d5ab14834576da96b9c2a9fa1.tar.gz rust-24368ecdc4c0248d5ab14834576da96b9c2a9fa1.zip | |
Auto merge of #105849 - matthiaskrgr:rollup-ya4s1n2, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #104854 (Symlink `build/host` -> `build/$HOST_TRIPLE`) - #105458 (Allow blocking `Command::output`) - #105559 (bootstrap: Allow installing `llvm-tools`) - #105789 (rustdoc: clean up margin CSS for scraped examples) - #105792 (docs: add long error explanation for error E0320) - #105814 (Support call and drop terminators in custom mir) - #105829 (Speed up tidy) - #105836 (std::fmt: Use args directly in example code) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys_common')
| -rw-r--r-- | library/std/src/sys_common/process.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/library/std/src/sys_common/process.rs b/library/std/src/sys_common/process.rs index 9f978789a62..ae11412067b 100644 --- a/library/std/src/sys_common/process.rs +++ b/library/std/src/sys_common/process.rs @@ -4,7 +4,9 @@ use crate::collections::BTreeMap; use crate::env; use crate::ffi::{OsStr, OsString}; -use crate::sys::process::EnvKey; +use crate::io; +use crate::sys::pipe::read2; +use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes}; // Stores a set of changes to an environment #[derive(Clone, Debug)] @@ -117,3 +119,30 @@ impl<'a> ExactSizeIterator for CommandEnvs<'a> { self.iter.is_empty() } } + +pub fn wait_with_output( + mut process: Process, + mut pipes: StdioPipes, +) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> { + drop(pipes.stdin.take()); + + let (mut stdout, mut stderr) = (Vec::new(), Vec::new()); + match (pipes.stdout.take(), pipes.stderr.take()) { + (None, None) => {} + (Some(out), None) => { + let res = out.read_to_end(&mut stdout); + res.unwrap(); + } + (None, Some(err)) => { + let res = err.read_to_end(&mut stderr); + res.unwrap(); + } + (Some(out), Some(err)) => { + let res = read2(out, &mut stdout, err, &mut stderr); + res.unwrap(); + } + } + + let status = process.wait()?; + Ok((status, stdout, stderr)) +} |
