I\'m starting a console application, but when I redirect the standard output I always get nothing!
When I don\'t redirect it, and set CreateNoWindow
to
Why are you looping? Once it's read to the end, it's not going to be able to read any more data, is it?
Are you sure the text is actually being written to StandardOutput
rather than StandardError
?
(And yes, obviously you want to set RedirectStandardOutput
to true rather than false. I assumed that was just a case of you copying the wrong version of your code.)
EDIT: As I've advised in the comments, you should read from standard output and standard error in separate threads. Do not wait until the process has exited - this can end up with a deadlock, where you're waiting for the process to exit, but the process is blocking trying to write to stderr/stdout because you haven't read from the buffer.
Alternatively you can subscribe to the OutputDataReceived and ErrorDataReceived events, to avoid using extra threads.