shell_tools/
lib.rs

1#[macro_export()]
2macro_rules! sh {
3    ($var:expr, $var2:expr) => {
4        let err = format!("Failed to execute {}", $var);
5        let output = Command::new("sh")
6            .arg("-c")
7            .arg($var)
8            .current_dir($var2.clone())
9            .output()
10            .expect(&err);
11
12        if output.status.success() {
13            // Print the stdout if the command executed successfully
14            let stdout = String::from_utf8_lossy(&output.stdout);
15            println!("{}", stdout);
16        } else {
17            // Print the stderr if the command failed
18            let stderr = String::from_utf8_lossy(&output.stderr);
19            println!("Command failed:\n{}", stderr);
20        }
21    };
22}