public static string ResolveFullExecutablePath(string fileName, bool returnNullOnFailure = true, params string[] extraPaths)
{
if (File.Exists(fileName))
return Path.GetFullPath(fileName);
if (executorType == ShellExecutorType.Windows)
{
var values = new List<string>(extraPaths);
values.AddRange(new List<string>(Environment.GetEnvironmentVariable("PATH").Split(';')));
foreach (var path in values)
{
var fullPath = Path.Combine(path, fileName);
if (File.Exists(fullPath))
return fullPath;
}
}
else
{
//Use the which command
var outputBuilder = new StringBuilder();
ExecuteShellCommand("which", $"\"{fileName}\"", (s, e) =>
{
outputBuilder.AppendLine(e.Data);
}, (s,e)=> { }, false);
var procOutput = outputBuilder.ToString();
if (string.IsNullOrWhiteSpace(procOutput))
{
return returnNullOnFailure ? null : fileName;
}
return procOutput.Trim();
}
return returnNullOnFailure ? null : fileName;
}
}