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