Skip to content

Commit

Permalink
Merge pull request #5 from perrylets/exit-code
Browse files Browse the repository at this point in the history
LGTM (Because I made it)
  • Loading branch information
perrylets authored Sep 7, 2023
2 parents bd1d263 + 03496a9 commit 579f082
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions CommandExec/CommandUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.IO;

namespace CommandExec
{
public static class CommandUtils
Expand All @@ -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;
}
}
}

0 comments on commit 579f082

Please sign in to comment.