using System.Diagnostics; namespace GB5DailyBuild; internal static class ProcessRunner { // Returns a negative sentinel (-1) instead of throwing when the executable // itself can't be found/started (e.g. sshpass not installed on this machine). // A missing tool on one machine must not crash the whole build+deploy run - // every caller already checks the exit code and reports a clean FAILED // result instead. public const int ExecutableNotFoundExitCode = -1; public static int Run(string fileName, string arguments, string workingDirectory, bool logCommand = true) { Console.WriteLine(logCommand ? $" $ {fileName} {arguments}" : $" $ {fileName} [arguments hidden]"); using var process = new Process { StartInfo = new ProcessStartInfo { FileName = fileName, Arguments = arguments, WorkingDirectory = workingDirectory, UseShellExecute = false, RedirectStandardOutput = false, RedirectStandardError = false, } }; try { process.Start(); } catch (System.ComponentModel.Win32Exception ex) { Console.WriteLine($" ! Could not start '{fileName}': {ex.Message}"); return ExecutableNotFoundExitCode; } process.WaitForExit(); return process.ExitCode; } }