1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
use subprocess::{Exec, Redirection};
// #[cfg(windows)]
// pub fn command_exists(cmd: &str) -> bool {
// let output = Exec::cmd("cmd").arg("/c").arg("where").arg(cmd)
// .stdout(Redirection::Pipe)
// .capture()
// .unwrap()
// .stdout_str();
// !output.is_empty()
// }
#[cfg(not(windows))]
pub fn command_exists(cmd: &str) -> bool {
let output = Exec::cmd("which").arg(cmd)
.stdout(Redirection::Pipe)
.capture()
.unwrap()
.stdout_str();
!output.is_empty()
}