~evan-hoose/Snippets

3ed24e9de899e8a14bcc151944ab932f1fe4f73a — Evan 11 months ago 3460cb0
 On branch master Changes to be committed:
	modified: shell.rs
1 files changed, 14 insertions(+), 2 deletions(-)

M shell.rs
M shell.rs => shell.rs +14 -2
@@ 1,9 1,21 @@
use std::process::Command;

fn shell(command: &str) {
    let status = Command::new("/bin/sh")
        .arg("-c")
        .arg(&command)
        .status()
        .expect("Unable to execute shell");

    println!("({}): {}", command, status);
    
    //As of writing this, status.success() only refers to whether or not the
    //exit code of the process is 0, regardless of 0's interpretation on a
    //given system.
    //
    //You are on a POSIX complient, I hope.
    //
    //If the exit code is not 0, print the command and status code for 
    //debugging.
    if !(status.success()) {
        println!("({}): {}", command, status);
    }
}