修正寻找可执行文件的bug

This commit is contained in:
nilaoda 2022-08-28 18:11:05 +08:00
parent 120f49fee2
commit 03c5ab3d74
1 changed files with 1 additions and 1 deletions

View File

@ -55,7 +55,7 @@ namespace N_m3u8DL_RE.Common.Util
public static string? FindExecutable(string name) public static string? FindExecutable(string name)
{ {
var fileExt = OperatingSystem.IsWindows() ? ".exe" : ""; var fileExt = OperatingSystem.IsWindows() ? ".exe" : "";
var searchPath = new[] { Environment.CurrentDirectory, Environment.ProcessPath }; var searchPath = new[] { Environment.CurrentDirectory, Path.GetDirectoryName(Environment.ProcessPath) };
var envPath = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) ?? var envPath = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) ??
Array.Empty<string>(); Array.Empty<string>();
return searchPath.Concat(envPath).Select(p => Path.Combine(p, name + fileExt)).FirstOrDefault(File.Exists); return searchPath.Concat(envPath).Select(p => Path.Combine(p, name + fileExt)).FirstOrDefault(File.Exists);