public static void Run(string program, string arguments, bool streamOutput = true, bool silent = false) { var exe = new InternalExe(program, arguments, streamOutput); if (!silent) { ColoredConsole.WriteLine($"> {program} {arguments}".Green()); } var exitcode = silent ? exe.Run() : exe.Run(l => ColoredConsole.Out.WriteLine(l.DarkGray()), e => ColoredConsole.Error.WriteLine(e.Red())); if (exitcode != 0) { throw new Exception($"{program} Exit Code == {exitcode}"); } }
public static string GetOutput(string program, string arguments, bool ignoreExitCode = false) { var exe = new InternalExe(program, arguments); var sb = new StringBuilder(); var exitCode = exe.Run(o => sb.AppendLine(o?.Trim()), e => ColoredConsole.Error.WriteLine(e.Red())); if (!ignoreExitCode && exitCode != 0) { throw new Exception($"{program} exit code == {exitCode}"); } return(sb.ToString().Trim(new[] { ' ', '\r', '\n' })); }