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