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
pub fn shell_exec(command_fields: Vec<String>) -> std::result::Result<i32, Box<dyn std::error::Error>> {
let mut command = std::process::Command::new("cmd");
let mut args: Vec<String> = vec![];
args.push("/C".to_string());
for e in command_fields {
args.push(e.to_string());
}
let mut command = command.args(args).spawn()?;
let response = command.wait();
if response.is_err() {
return Err(Box::new(response.err().unwrap()));
}
let status = response.unwrap();
if !status.success() {
let exit_code = status.code().unwrap();
println!("[ERROR] command exited with status: {}", exit_code);
return Ok(exit_code);
}
return Ok(0);
}
pub fn read_text_file_all(path: &str) -> std::result::Result<String, Box<dyn std::error::Error>> {
use std::io::Read;
let mut file = std::fs::File::open(path)?;
let mut s = String::new();
file.read_to_string(&mut s)?;
return Ok(s);
}
pub fn select(left: &str, right: &str) -> String {
return match left {
"" => String::from(right),
_ => String::from(left),
};
}