Robert Muehsig
2017-11-15 23:42:15 +01:00
parent d1b42fa007
commit 5c14e585cf
4 changed files with 34 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ namespace ElectronNET.CLI
{
public class ProcessHelper
{
public static void CmdExecute(string command, string workingDirectoryPath, bool output = true, bool waitForExit = true)
public static int CmdExecute(string command, string workingDirectoryPath, bool output = true, bool waitForExit = true)
{
using (Process cmd = new Process())
{
@@ -28,10 +28,21 @@ namespace ElectronNET.CLI
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.WorkingDirectory = workingDirectoryPath;
int returnCode = 0;
if (output)
{
cmd.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
cmd.ErrorDataReceived += (s, e) => Console.WriteLine(e.Data);
cmd.ErrorDataReceived += (s, e) =>
{
// we can't just use cmd.ExitCode, because
// we delegate it to cmd.exe, which runs fine
// but we can catch any error here and return
// 1 if something fails
returnCode = 1;
Console.WriteLine(e.Data);
};
}
cmd.Start();
@@ -46,6 +57,8 @@ namespace ElectronNET.CLI
{
cmd.WaitForExit();
}
return returnCode;
}
}
}