I have an executable, which runs fine when i run it manually, and it exists as it should with the expected output. But when i run it with the method bellow, the Process.Exit
There's a deadlock in your code. 'Standard output' is just a kind of named pipe, which has a small buffer to transfer data from one process to the other. If the buffer is full, the writing process has to wait for the reading process to retrieve some data from the buffer.
So the process you have started might wait for you to read from the standard output, but you are waiting for the process to finish before you start reading -> deadlock.
The solution is to read continuously while the process is running - just call StandardOutput.ReadToEnd()
before you call WaitForExit()
.
If you want to read without blocking the current thread, you can use BeginOutputReadLine()
and the OutputDataReceived
events.