os/
information.rs

1use std::process::Command;
2
3#[derive(Debug)]
4pub struct OSInfo {
5    pub kernel_name: String,
6    pub os_name: String,
7}
8
9pub fn get_info() -> OSInfo {
10    let output = Command::new("uname")
11                         .arg("-a")
12                         .output()
13                         .expect("Failed to get OS info");
14
15    parse_info(String::from_utf8(output.stdout).unwrap())
16}
17
18fn parse_info(string: String) -> OSInfo {
19    let info: Vec<&str> = string.trim().split(" ").collect();
20    
21    OSInfo {
22        kernel_name: info.first().unwrap().to_string(),
23        os_name: info.last().unwrap().to_string(),
24    }
25}