Skip to content

Commit 22e2ab3

Browse files
authored
fix hostname
1 parent 12ff191 commit 22e2ab3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ pub fn username() -> String {
1717

1818
#[cfg(target_family = "unix")]
1919
pub fn hostname() -> Result<String, ()> {
20-
Ok(var("HOSTNAME").unwrap())
20+
let output = Command::new("hostname")
21+
.output();
22+
23+
match output {
24+
Ok(output) => return Ok(String::from_utf8(output.stdout).unwrap()),
25+
Err(_) => return Err(()),
26+
}
2127
}
2228

2329
#[cfg(target_family = "windows")]
@@ -135,4 +141,4 @@ macro_rules! printlnr {
135141
($($arg:tt)*) => ({
136142
println!("{}\x1b[0m", format_args!($($arg)*));
137143
})
138-
}
144+
}

0 commit comments

Comments
 (0)