schultyy / os_type

Rust library to detect the operating system type
MIT License
30 stars 18 forks source link

Check for BSDs #34

Open rgeorgia opened 5 years ago

rgeorgia commented 5 years ago

We could add support of BSD by invoking uname -s and uname -a. Now, I am so new to Rust I can barely spell it. I am not even sure how I can add this to os_type to test it out. Any hand holding would be accepted. Here is what I have. It works for NetBSD, OpenBSD, FreeBSD, well any BSD derivative. fn get_os_bsd() {

let nb_output = Command::new("uname").arg("-s").output()
    .expect("failed to execute uname") ;

println!("OS stdout: {}", String::from_utf8_lossy(&nb_output.stdout)) ;

}

fn get_bsd_version() {

let nb_output = Command::new("uname").arg("-r").output()
    .expect("failed to execute uname") ;

println!("Version stdout: {}", String::from_utf8_lossy(&nb_output.stdout)) ;

}

OUTPUT: Mac (our solution much better) OS stdout: Darwin Version stdout: 18.2.0

NetBSD: OS stdout: NetBSD Version stdout: 8.99.35

FreeBSD: OS stdout: FreeBSD Version stdout: 12.0-RELEASE

OpenBSD: OS stdout: OpenBSD Version stdout: 6.4

rgeorgia commented 5 years ago

DragonFlyBSD: OS stdout: DragonFly Version stdout: 5.4-RELEASE