简体   繁体   中英

Can I merge the standard output and standard error of a Process with the output of a console window in C#?

I am starting a process via Process.Start and redirecting the standard output. I have access to the standard output via the standard output stream on the process instance, but I have to keep checking for it. Is it possible to redirect that output to the standard output of my console window?

If I'm understanding your question right, you're saying you're redirecting the standard output but you have to keep reading from that stream to stop the process from blocking when the buffer gets full. You don't want to keep reading, so you are looking for a way to redirect the standard output to the console window?

In that case, why not just not redirect the standard output? Isn't the console window where it will go if you don't redirect it?

If you have to redirect the standard output, the best way might be to put a delegate on the threadpool to read from the standard output stream. If you just want to read all the output, you can call ReadToEnd. If you want to display it as well as having access to the output in your code, you could read and then write it to the console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM