C#中如何重定向数据流控制台输出? [英] C# How to redirect stream to the console Out?
本文介绍了C#中如何重定向数据流控制台输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现很多样本如何控制台输出重定向到一个文件中。不过,我需要一个相对soluiton - 我的StreamWriter,我要显示在控制台输出,一旦我做sw.WriteLine(文字);
I found lots of samples how to redirect console output into a file. However I need an opposite soluiton - I have StreamWriter which I want to be shown in the Console output once I do sw.WriteLine("text");
推荐答案
只需指向流到标准输出:
Just point the stream to standard output:
sw = new StreamWriter(Console.OpenStandardOutput());
sw.AutoFlush = true;
Console.SetOut(sw);
这篇关于C#中如何重定向数据流控制台输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文