How to write to a program's StdOut Stream directly in C#?

前端 未结 3 720
无人共我
无人共我 2021-01-02 21:46

I know that there\'re stdout/in/err for a program and I want to redirect a program\'s output to a file instead of the console output. And I now figure it out with the code b

3条回答
  •  一生所求
    2021-01-02 22:05

    You probably shouldn't set the stdout of your own process. The reason it's stdout is so that the caller (command line, whatever) can redirect it wherever it needs to, without your program having to know.

    That's how things like "type foo.txt | more" work. If the type command felt free to redefine stdout to a file, that wouldn't work at all.

    If you want to write to a stream, just open the stream and write to it.

提交回复
热议问题