blob: 355750540e7d1ad6c82e69d2a3e54e4acfe7a537 (
plain)
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
|
#[macro_export]
macro_rules! task {
($verse:expr, $out:expr) => {
if $verse.couplet {
let mut child = Command::new($verse.verb())
.args($verse.clause())
.stdin(Stdio::piped())
.spawn()
.map_err(|e| match e.kind() {
io::ErrorKind::PermissionDenied => Mishap::PermissionDenied($verse.verb()),
_ => Mishap::Else($verse.verb()),
})?;
let stdin = child
.stdin
.as_mut()
.ok_or(Mishap::BrokenPipe($verse.verb()))?;
stdin
.write_all(&$out.as_bytes())
.map_err(|_| Mishap::BrokenPipe($verse.verb()))?;
$out.clear();
child
} else {
Command::new($verse.verb())
.args($verse.clause())
.spawn()
.map_err(|e| match e.kind() {
io::ErrorKind::PermissionDenied => Mishap::PermissionDenied($verse.verb()),
_ => Mishap::Else($verse.verb()),
})?
}
};
}
#[macro_export()]
macro_rules! ctask {
($verse:expr, $out:expr) => {
if $verse.couplet {
let mut child = Command::new($verse.verb())
.args($verse.clause())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.map_err(|e| match e.kind() {
io::ErrorKind::PermissionDenied => Mishap::PermissionDenied($verse.verb()),
_ => Mishap::Else($verse.verb()),
})?;
let stdin = child
.stdin
.as_mut()
.ok_or(Mishap::BrokenPipe($verse.verb()))?;
stdin
.write_all(&$out.as_bytes())
.map_err(|_| Mishap::BrokenPipe($verse.verb()))?;
$out.clear();
child
} else {
Command::new($verse.verb())
.args($verse.clause())
.stdout(Stdio::piped())
.spawn()
.map_err(|e| match e.kind() {
io::ErrorKind::PermissionDenied => Mishap::PermissionDenied($verse.verb()),
_ => Mishap::Else($verse.verb()),
})?
}
};
}
|