1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
use std::ffi::OsStr;
use std::io::Error as IoError;
use std::path::Path;
use std::process;
use std::process::Stdio;
use std::process::{Child, Command};
use ext::{ChildExt, CommandExt, Error, Output};
#[derive(Debug)]
pub struct CheckedChild {
child: Child,
}
impl From<Child> for CheckedChild {
fn from(child: Child) -> CheckedChild {
CheckedChild { child }
}
}
impl CheckedChild {
pub fn as_std_command(&mut self) -> &mut Child {
&mut self.child
}
pub fn into_std_command(self) -> Child {
self.child
}
pub fn stdin(&mut self) -> &mut Option<process::ChildStdin> {
&mut self.child.stdin
}
pub fn stdout(&mut self) -> &mut Option<process::ChildStdout> {
&mut self.child.stdout
}
pub fn stderr(&mut self) -> &mut Option<process::ChildStderr> {
&mut self.child.stderr
}
pub fn kill(&mut self) -> Result<(), IoError> {
self.child.kill()
}
pub fn id(&self) -> u32 {
self.child.id()
}
pub fn wait(&mut self) -> Result<(), Error> {
self.child.checked_wait()
}
#[cfg(feature = "process_try_wait")]
pub fn try_wait(&mut self) -> Result<bool, Error> {
self.child.checked_try_wait()
}
pub fn wait_with_output(self) -> Result<Output, Error> {
self.child.checked_wait_with_output()
}
}
#[derive(Debug)]
pub struct CheckedCommand {
command: Command,
}
impl From<Command> for CheckedCommand {
fn from(command: Command) -> CheckedCommand {
CheckedCommand { command }
}
}
impl CheckedCommand {
pub fn as_std_command(&mut self) -> &mut Command {
&mut self.command
}
pub fn into_std_command(self) -> Command {
self.command
}
pub fn new<S: AsRef<OsStr>>(program: S) -> CheckedCommand {
CheckedCommand {
command: Command::new(program),
}
}
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut CheckedCommand {
self.command.arg(arg);
self
}
pub fn args<I, S>(&mut self, args: I) -> &mut CheckedCommand
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
self.command.args(args);
self
}
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut CheckedCommand
where
K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
self.command.env(key, val);
self
}
#[cfg(feature = "command_envs")]
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut CheckedCommand
where
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
self.command.envs(vars);
self
}
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut CheckedCommand {
self.command.env_remove(key);
self
}
pub fn env_clear(&mut self) -> &mut CheckedCommand {
self.command.env_clear();
self
}
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut CheckedCommand {
self.command.current_dir(dir);
self
}
pub fn stdin(&mut self, cfg: Stdio) -> &mut CheckedCommand {
self.command.stdin(cfg);
self
}
pub fn stdout(&mut self, cfg: Stdio) -> &mut CheckedCommand {
self.command.stdout(cfg);
self
}
pub fn stderr(&mut self, cfg: Stdio) -> &mut CheckedCommand {
self.command.stderr(cfg);
self
}
pub fn spawn(&mut self) -> Result<CheckedChild, IoError> {
self.command.spawn().map(Into::into)
}
pub fn output(&mut self) -> Result<Output, Error> {
self.command.checked_output()
}
pub fn status(&mut self) -> Result<(), Error> {
self.command.checked_status()
}
}