From b6cf4070b6635a20d4fd5a78c9076243d889b53c Mon Sep 17 00:00:00 2001 From: flavio Date: Fri, 23 Sep 2022 22:14:18 -0300 Subject: [PATCH] fix possibility of dead lock in ProcessStart see: https://stackoverflow.com/a/139604/7335274 --- ModernRonin.ProjectRenamer/Executor.cs | 2 +- ModernRonin.ProjectRenamer/IRuntime.cs | 2 +- ModernRonin.ProjectRenamer/Runtime.cs | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ModernRonin.ProjectRenamer/Executor.cs b/ModernRonin.ProjectRenamer/Executor.cs index ac73692..b880c5b 100644 --- a/ModernRonin.ProjectRenamer/Executor.cs +++ b/ModernRonin.ProjectRenamer/Executor.cs @@ -26,7 +26,7 @@ public string ToolRead(string tool, string arguments, Action onNonZeroExitCode) { var result = string.Empty; _runtime.DoWithTool(tool, arguments, onNonZeroExitCode, psi => psi.RedirectStandardOutput = true, - p => result = p.StandardOutput.ReadToEnd()); + p => result = p); return result; } } diff --git a/ModernRonin.ProjectRenamer/IRuntime.cs b/ModernRonin.ProjectRenamer/IRuntime.cs index 4ad82ac..21608dc 100644 --- a/ModernRonin.ProjectRenamer/IRuntime.cs +++ b/ModernRonin.ProjectRenamer/IRuntime.cs @@ -11,6 +11,6 @@ void DoWithTool(string tool, string arguments, Action onNonZeroExitCode, Action configure, - Action onSuccess); + Action onSuccess); } } \ No newline at end of file diff --git a/ModernRonin.ProjectRenamer/Runtime.cs b/ModernRonin.ProjectRenamer/Runtime.cs index ff132e4..337207e 100644 --- a/ModernRonin.ProjectRenamer/Runtime.cs +++ b/ModernRonin.ProjectRenamer/Runtime.cs @@ -17,7 +17,7 @@ public void DoWithTool(string tool, string arguments, Action onNonZeroExitCode, Action configure, - Action onSuccess) + Action onSuccess) { var psi = new ProcessStartInfo { @@ -30,9 +30,13 @@ public void DoWithTool(string tool, try { var process = Process.Start(psi); + string output = ""; + if (psi.RedirectStandardOutput) + output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); if (process.ExitCode != 0) onNonZeroExitCode(); - else onSuccess(process); + else onSuccess(output); } catch (Win32Exception) {