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