diff options
| author | joboet <jonasboettiger@icloud.com> | 2025-03-27 14:20:25 +0100 |
|---|---|---|
| committer | joboet <jonasboettiger@icloud.com> | 2025-04-28 11:13:50 +0200 |
| commit | 5f145689b1c0a313ee737de296a57d1479c18cb5 (patch) | |
| tree | 3e211a503c830d0c0d0a3470b55dab6b3ffafb63 /library/std/src/sys/process/mod.rs | |
| parent | 0134651fb81314870903e21b1bcbdd993d75b61a (diff) | |
| download | rust-5f145689b1c0a313ee737de296a57d1479c18cb5.tar.gz rust-5f145689b1c0a313ee737de296a57d1479c18cb5.zip | |
std: get rid of `sys_common::process`
Move the public `CommandEnvs` into the `process` module (and make it a wrapper type for an internal iterator type) and everything else into `sys::process` as per #117276.
Diffstat (limited to 'library/std/src/sys/process/mod.rs')
| -rw-r--r-- | library/std/src/sys/process/mod.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/library/std/src/sys/process/mod.rs b/library/std/src/sys/process/mod.rs index 92cfac7f47c..91c7005a328 100644 --- a/library/std/src/sys/process/mod.rs +++ b/library/std/src/sys/process/mod.rs @@ -14,6 +14,65 @@ cfg_if::cfg_if! { } } +// This module is shared by all platforms, but nearly all platforms except for +// the "normal" UNIX ones leave some of this code unused. +#[cfg_attr(not(target_os = "linux"), allow(dead_code))] +mod env; + +pub use env::CommandEnvs; pub use imp::{ Command, CommandArgs, EnvKey, ExitCode, ExitStatus, ExitStatusError, Process, Stdio, StdioPipes, }; + +#[cfg(any( + all( + target_family = "unix", + not(any( + target_os = "espidf", + target_os = "horizon", + target_os = "vita", + target_os = "nuttx" + )) + ), + target_os = "windows", +))] +pub fn output(cmd: &mut Command) -> crate::io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> { + use crate::sys::pipe::read2; + + let (mut process, mut pipes) = cmd.spawn(Stdio::MakePipe, false)?; + + 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)) +} + +#[cfg(not(any( + all( + target_family = "unix", + not(any( + target_os = "espidf", + target_os = "horizon", + target_os = "vita", + target_os = "nuttx" + )) + ), + target_os = "windows", +)))] +pub use imp::output; |
