Skip to content

Commit b98168a

Browse files
committed
Enabled debug logging for executable tasks
1 parent 44ca84f commit b98168a

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

Program.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,27 @@ private static bool ExecuteExecutable(string executablePath, string arguments, b
578578
try
579579
{
580580
var timer = new Timer();
581-
var process = new Process { StartInfo = { CreateNoWindow = !showWindow, FileName = executablePath, Arguments = arguments} };
582-
process.Start();
583-
if (!process.WaitForExit(Convert.ToInt32(TimeSpan.FromDays(1).TotalMilliseconds)))
581+
var process = new Process
584582
{
585-
Log.Error("Scheduler executable task didn't end on its own: " + executablePath);
586-
process.Kill();
587-
}
583+
StartInfo =
584+
{
585+
FileName = executablePath,
586+
Arguments = arguments,
587+
CreateNoWindow = !showWindow,
588+
RedirectStandardError = true,
589+
RedirectStandardOutput = true,
590+
UseShellExecute = false
591+
}
592+
};
593+
process.OutputDataReceived += ExecutableOutputDataReceivedHandler;
594+
process.ErrorDataReceived += ExecutableErrorDataReceivedHandler;
595+
process.Start();
596+
process.BeginOutputReadLine();
597+
process.BeginErrorReadLine();
598+
process.WaitForExit();
599+
588600
timer.Stop();
601+
589602
return (Utilities.SynchronisationTaskExitCode) process.ExitCode == Utilities.SynchronisationTaskExitCode.Success;
590603
}
591604
catch (Exception ex)
@@ -773,6 +786,17 @@ private static void VbsOutputDataReceivedHandler(object sender, DataReceivedEven
773786
{
774787
Log.Debug($"{LoggingPrefix}VBS: {e.Data}");
775788
}
789+
790+
private static void ExecutableErrorDataReceivedHandler(object sender, DataReceivedEventArgs e)
791+
{
792+
if (e != null && !string.IsNullOrEmpty(e.Data))
793+
Log.Error($"{LoggingPrefix}Executable: {e.Data}");
794+
}
795+
796+
private static void ExecutableOutputDataReceivedHandler(object sender, DataReceivedEventArgs e)
797+
{
798+
Log.Debug($"{LoggingPrefix}Executable: {e.Data}");
799+
}
776800
#endregion
777801
}
778802
}

0 commit comments

Comments
 (0)