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