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#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
27mod env;
28
29pub use env::CommandEnvs;
30#[cfg(target_family = "unix")]
31pub use imp::getppid;
32pub use imp::{
33 ChildPipe, Command, CommandArgs, EnvKey, ExitCode, ExitStatus, ExitStatusError, Process, Stdio,
34 getpid, read_output,
35};
36
37#[cfg(any(
38 all(
39 target_family = "unix",
40 not(any(
41 target_os = "espidf",
42 target_os = "horizon",
43 target_os = "vita",
44 target_os = "nuttx"
45 ))
46 ),
47 target_os = "windows",
48 target_os = "motor"
49))]
50pub fn output(cmd: &mut Command) -> crate::io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
51 let (mut process, mut pipes) = cmd.spawn(Stdio::MakePipe, false)?;
52
53 drop(pipes.stdin.take());
54 let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
55 match (pipes.stdout.take(), pipes.stderr.take()) {
56 (None, None) => {}
57 (Some(out), None) => {
58 let res = out.read_to_end(&mut stdout);
59 res.unwrap();
60 }
61 (None, Some(err)) => {
62 let res = err.read_to_end(&mut stderr);
63 res.unwrap();
64 }
65 (Some(out), Some(err)) => {
66 let res = read_output(out, &mut stdout, err, &mut stderr);
67 res.unwrap();
68 }
69 }
70
71 let status = process.wait()?;
72 Ok((status, stdout, stderr))
73}
74
75#[cfg(not(any(
76 all(
77 target_family = "unix",
78 not(any(
79 target_os = "espidf",
80 target_os = "horizon",
81 target_os = "vita",
82 target_os = "nuttx"
83 ))
84 ),
85 target_os = "windows",
86 target_os = "motor"
87)))]
88pub use imp::output;