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
#[macro_export]
macro_rules! sh { ( $( $cmd:tt )* ) => { $crate::execute_with("sh", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! ash { ( $( $cmd:tt )* ) => { $crate::execute_with("ash", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! csh { ( $( $cmd:tt )* ) => { $crate::execute_with("csh", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! ksh { ( $( $cmd:tt )* ) => { $crate::execute_with("ksh", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! zsh { ( $( $cmd:tt )* ) => { $crate::execute_with("zsh", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! bash { ( $( $cmd:tt )* ) => { $crate::execute_with("bash", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! dash { ( $( $cmd:tt )* ) => { $crate::execute_with("dash", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! fish { ( $( $cmd:tt )* ) => { $crate::execute_with("fish", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! mksh { ( $( $cmd:tt )* ) => { $crate::execute_with("mksh", &format!($( $cmd )*)) }; }
#[macro_export]
macro_rules! tcsh { ( $( $cmd:tt )* ) => { $crate::execute_with("tcsh", &format!($( $cmd )*)) }; }
#[doc(hidden)]
pub fn execute_with(shell: &str, cmd: &String) -> (i32, String, String) {
let mut command = {
let mut command = ::std::process::Command::new(shell);
command.arg("-c").arg(cmd);
command
};
match command.output() {
Ok(output) => {
(output.status.code().unwrap_or(if output.status.success() { 0 } else { 1 }),
String::from_utf8_lossy(&output.stdout[..]).into_owned(),
String::from_utf8_lossy(&output.stderr[..]).into_owned())
},
Err(e) => (126, String::new(), e.to_string()),
}
}