diff --git a/CommandExec/CommandUtils.cs b/CommandExec/CommandUtils.cs index 2ae25d9..4b1b839 100644 --- a/CommandExec/CommandUtils.cs +++ b/CommandExec/CommandUtils.cs @@ -1,6 +1,3 @@ -using System; -using System.IO; - namespace CommandExec { public static class CommandUtils @@ -10,15 +7,21 @@ public static bool CommandExists(string command) Command cmd; if (Command.isUnix) { - cmd = Command.Shell($"command -v {command} &> /dev/null && echo true").RedirectStdOut(); + cmd = Command.Shell($"command -v {command} &> /dev/null").RedirectStdOut() + .RedirectStdOut() + .RedirectStdErr() + .RedirectStdIn(); } else { - cmd = Command.Shell($"if (Get-Command -Name {command} -ErrorAction SilentlyContinue) {{echo true}}").RedirectStdOut(); + cmd = Command.Shell($"Get-Command -Name {command} -ErrorAction SilentlyContinue > $null") + .RedirectStdOut() + .RedirectStdErr() + .RedirectStdIn(); } cmd.Run(); - return cmd.STDOut.ReadToEnd().ReplaceLineEndings("") == "true"; + return cmd.process.ExitCode == 0; } } }