pub fn resolve_program(
program: &OsStr,
search_path: Option<&OsStr>,
) -> Option<PathBuf>Expand description
Where Command::new(program) would find program, or None if it would not.
search_path is the PATH value to search, normally the environment’s; it is
a parameter so the lookup can be exercised against a controlled directory.
On unix this follows execvp: a name containing a slash is taken as a path
and never searched for, anything else is looked up in each PATH entry in
order (an empty entry meaning the current directory), and a match must be a
regular file with an execute bit. When PATH is unset the libc default
/usr/bin:/bin applies.
On windows this follows the standard library’s own resolution. A name with a
path separator is never searched for: one ending in .exe is used as written,
any other is tried with .exe appended to the name as written and then as
written. A bare name is searched in the directory of the running executable,
the system directory, the Windows directory and then each PATH entry, in
that order, with .exe appended when the name contains no . at all; the
working directory is not searched. PATHEXT is deliberately not consulted,
because Command::new does not consult it either: a tool.cmd shim is not
something the spawn would find under the bare name.