Skip to content

Commit

Permalink
Merge pull request #39 from fsbflavio/fix-deadlock-psi
Browse files Browse the repository at this point in the history
fix possibility of dead lock in ProcessStart
  • Loading branch information
ModernRonin authored Sep 24, 2022
2 parents 99e5e3d + b6cf407 commit 99eea45
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 99eea45

Please sign in to comment.