I am working with C# and having trouble understanding how to read stdout asynchronously from a child process. What I want to do is create a child process that execu
The exception you get is normal. One BeginRead()
call can never succeed: the last one, just after the process terminates. You'd normally avoid calling BeginRead()
again if you know the process is completed so you don't get the exception. However, you'd rarely know. Just catch the exception. Or use BeginOutputReadLine()
instead, it will catch it for you.
I'm guessing that you also redirect stderr and that the tool uses it to output "X". There is no way to keep output on both stderr and stdout synchronized after it is buffered and redirected.