C# Read stdout of child process asynchronously

后端 未结 1 1197
梦如初夏
梦如初夏 2020-12-18 06:23

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

1条回答
  •  囚心锁ツ
    2020-12-18 06:46

    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.

    0 讨论(0)
提交回复
热议问题