fix: fallback to stdout if stderr is empty

This commit is contained in:
iff 2024-09-24 18:28:13 +02:00
parent 96a588799d
commit adfedfad3d

View file

@ -26,12 +26,23 @@ pub fn command_output(shell: &str, command: &str) -> String {
}); });
match receiver.recv_timeout(Duration::from_secs(3)) { match receiver.recv_timeout(Duration::from_secs(3)) {
Ok(output) => String::from_utf8_lossy(&output.stderr) Ok(output) => {
.to_string() if !output.stderr.is_empty() {
.split_whitespace() String::from_utf8_lossy(&output.stderr)
.collect::<Vec<&str>>() .to_string()
.join(" ") .split_whitespace()
.to_lowercase(), .collect::<Vec<&str>>()
.join(" ")
.to_lowercase()
} else {
String::from_utf8_lossy(&output.stdout)
.to_string()
.split_whitespace()
.collect::<Vec<&str>>()
.join(" ")
.to_lowercase()
}
}
Err(_) => { Err(_) => {
use colored::*; use colored::*;
eprintln!("Timeout while executing command: {}", command.red()); eprintln!("Timeout while executing command: {}", command.red());