Skip to content

Commit

Permalink
fix possibility of dead lock in ProcessStart
Browse files Browse the repository at this point in the history
  • Loading branch information
flavio committed Sep 24, 2022
1 parent 99e5e3d commit b6cf407
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ModernRonin.ProjectRenamer/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ModernRonin.ProjectRenamer/IRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ void DoWithTool(string tool,
string arguments,
Action onNonZeroExitCode,
Action<ProcessStartInfo> configure,
Action<Process> onSuccess);
Action<string> onSuccess);
}
}
8 changes: 6 additions & 2 deletions ModernRonin.ProjectRenamer/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void DoWithTool(string tool,
string arguments,
Action onNonZeroExitCode,
Action<ProcessStartInfo> configure,
Action<Process> onSuccess)
Action<string> onSuccess)
{
var psi = new ProcessStartInfo
{
Expand All @@ -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)
{
Expand Down

0 comments on commit b6cf407

Please sign in to comment.