Class CommandAvailability
- Namespace
- Utils.Reflection.ProcessIsolation
- Assembly
- Utils.Reflection.dll
Provides helpers to locate command-line executables in the current process environment.
public static class CommandAvailability
- Inheritance
-
CommandAvailability
- Inherited Members
Methods
Exists(string)
Returns true when an executable is present in PATH.
public static bool Exists(string commandName)
Parameters
commandNamestringFile name of the executable to probe.
Returns
Remarks
On Windows, when commandName has no extension, each extension listed in
PATHEXT is also tried (matching how cmd.exe/CreateProcess resolve a bare
command name), so Exists("ffmpeg") finds ffmpeg.exe without the caller having to
know the platform-specific executable extension.
TryResolve(string, out string?)
Locates an executable in PATH and returns its canonical absolute path.
public static bool TryResolve(string commandName, out string? absolutePath)
Parameters
commandNamestringFile name or rooted path of the executable to locate.
absolutePathstringWhen this method returns true, the canonical absolute path to the executable; otherwise null.
Returns
Remarks
Callers should retain the resolved path and pass it directly to process launches rather than
re-resolving the bare command name each time. Re-resolving introduces a TOCTOU window: the
PATH value or the file at each candidate directory can change between the check and the
launch, allowing a different (possibly hostile) binary to be executed.
On Windows, when commandName has no extension, each extension listed in
PATHEXT is also tried; see Exists(string) for details.