Function which::which_global

source ·
pub fn which_global<T: AsRef<OsStr>>(binary_name: T) -> Result<PathBuf>
Expand description

Find an executable binary’s path by name, ignoring cwd.

If given an absolute path, returns it if the file exists and is executable.

Does not resolve relative paths.

If given a string without path separators, looks for a file named binary_name at each directory in $PATH and if it finds an executable file there, returns it.


use which::which;
use std::path::PathBuf;

let result = which::which_global("rustc").unwrap();
assert_eq!(result, PathBuf::from("/usr/bin/rustc"));