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 ))
50 ),
51 target_os = "windows",
52 target_os = "motor"
53))]
54pub fn output(cmd: &mut Command) -> crate::io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
55 let (mut process, mut pipes) = cmd.spawn(Stdio::MakePipe, false)?;
56
57 drop(pipes.stdin.take());
58 let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
59 match (pipes.stdout.take(), pipes.stderr.take()) {
60 (None, None) => {}
61 (Some(out), None) => {
62 let res = out.read_to_end(&mut stdout);
63 res.unwrap();
64 }
65 (None, Some(err)) => {
66 let res = err.read_to_end(&mut stderr);
67 res.unwrap();
68 }
69 (Some(out), Some(err)) => {
70 let res = read_output(out, &mut stdout, err, &mut stderr);
71 res.unwrap();
72 }
73 }
74
75 let status = process.wait()?;
76 Ok((status, stdout, stderr))
77}
78
79#[cfg(not(any(
80 all(
81 target_family = "unix",
82 not(any(
83 target_os = "espidf",
84 target_os = "horizon",
85 target_os = "vita",
86 target_os = "nuttx"
87 ))
88 ),
89 target_os = "windows",
90 target_os = "motor"
91)))]
92pub use imp::output;