std/sys/process/
mod.rs

1cfg_select! {
2    target_family = "unix" => {
3        mod unix;
4        use unix as imp;
5    }
6    target_os = "windows" => {
7        mod windows;
8        use windows as imp;
9    }
10    target_os = "uefi" => {
11        mod uefi;
12        use uefi as imp;
13    }
14    target_os = "motor" => {
15        mod motor;
16        use motor as imp;
17    }
18    _ => {
19        mod unsupported;
20        use unsupported as imp;
21    }
22}
23
24// This module is shared by all platforms, but nearly all platforms except for
25// the "normal" UNIX ones leave some of this code unused.
26#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
27mod env;
28
29pub use env::CommandEnvs;
30pub use imp::{
31    Command, CommandArgs, EnvKey, ExitCode, ExitStatus, ExitStatusError, Process, Stdio,
32};
33
34#[cfg(any(
35    all(
36        target_family = "unix",
37        not(any(
38            target_os = "espidf",
39            target_os = "horizon",
40            target_os = "vita",
41            target_os = "nuttx"
42        ))
43    ),
44    target_os = "windows",
45    target_os = "motor"
46))]
47pub fn output(cmd: &mut Command) -> crate::io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
48    use crate::sys::pipe::read2;
49
50    let (mut process, mut pipes) = cmd.spawn(Stdio::MakePipe, false)?;
51
52    drop(pipes.stdin.take());
53    let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
54    match (pipes.stdout.take(), pipes.stderr.take()) {
55        (None, None) => {}
56        (Some(out), None) => {
57            let res = out.read_to_end(&mut stdout);
58            res.unwrap();
59        }
60        (None, Some(err)) => {
61            let res = err.read_to_end(&mut stderr);
62            res.unwrap();
63        }
64        (Some(out), Some(err)) => {
65            let res = read2(out, &mut stdout, err, &mut stderr);
66            res.unwrap();
67        }
68    }
69
70    let status = process.wait()?;
71    Ok((status, stdout, stderr))
72}
73
74#[cfg(not(any(
75    all(
76        target_family = "unix",
77        not(any(
78            target_os = "espidf",
79            target_os = "horizon",
80            target_os = "vita",
81            target_os = "nuttx"
82        ))
83    ),
84    target_os = "windows",
85    target_os = "motor"
86)))]
87pub use imp::output;