Unity debugger hangs when using System.Diagnostics.Process
I'm using following code to start process:
var startInfo = new ProcessStartInfo(executablePath);
startInfo.WorkingDirectory = Path.GetDirectoryName(executablePath);
startInfo.FileName = executablePath;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.Arguments = arguments;
startInfo.CreateNoWindow = true;
_process = new Process();
_process.EnableRaisingEvents = false;
_process.StartInfo = startInfo;
_process.OutputDataReceived += _process_OutputDataReceived;
_process.ErrorDataReceived += _process_ErrorDataReceived;
_process.Start();
_process.StandardInput.Close();
_process.StandardError.Close();
_process.BeginOutputReadLine();
Everything works fine without a debugger attached. As soon as I attach the visual studio debugger with a breakpoint Unity (and VS) freezes. It only reaches the breakpoint when _process writes something to its standard output.
When I remove _process.BeginOutputReadLine(); then the debugger works correctly. I would like to be able to use visual studio debugger when I debug scripts.
Am I doing something wrong? Or is there some workaround for this?
Too bad there is no answer to this problem. I have the same problem and looking for a solution for hours. I have a little hope but asking here if you remember how you solved this issue. Thanks
If I remember correctly, the problem was not in the VS but in the process itself. The process was waiting for inco$$anonymous$$g data which, I guess, had blocking behavior. I had to send some data to the process just to keep it alive. I think I ended up constantly sending "DONT_GET_STUCK" string message :D to the process. I'm not really sure though if that was the solution. Just recalled that I did something like that. Hope that helps.
Your answer
Follow this Question
Related Questions
Unity permanently locks up when hitting a break point 1 Answer
Unity Editor freezes when starting several System.Diagnostics.Process one after another 0 Answers
Unity instance missing in "Attach Unity Debugger", Visual Studio 2013. How do I fix this? 6 Answers
5.3 Unity Editor Freeze on First Play 5 Answers
Unity freezing after update when trying to use sprites. 0 Answers