Skip to content

Commit

Permalink
Fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangSpivey committed Jan 2, 2017
1 parent c6c0b48 commit 1e2912f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Source/UtilsCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ private UtilsCommon ()
process.StartInfo.RedirectStandardError = true;
process.Start();

if(stderrInsteadOfStdout) return process.StandardError.ReadToEnd() ?? "";
else return process.StandardOutput.ReadToEnd() ?? "";
if(stderrInsteadOfStdout) {
process.BeginOutputReadLine(); // avoids deadlock (see https://msdn.microsoft.com/de-de/library/system.diagnostics.processstartinfo.redirectstandardoutput(v=vs.110).aspx)
return process.StandardError.ReadToEnd() ?? "";
}
else {
process.BeginErrorReadLine(); // avoids deadlock (see https://msdn.microsoft.com/de-de/library/system.diagnostics.processstartinfo.redirectstandardoutput(v=vs.110).aspx)
return process.StandardOutput.ReadToEnd() ?? "";
}
} catch(Exception e1) {
if(printError) Console.Write("\"" + exePath + " " + args + "\" failed\n" + e1);

Expand Down

0 comments on commit 1e2912f

Please sign in to comment.