有没有办法写一个控制台应用程序时,创建第二个控制台输出到.NET? [英] Is there a way to create a second console to output to in .NET when writing a console application?

查看:127
本文介绍了有没有办法写一个控制台应用程序时,创建第二个控制台输出到.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来创建第二个控制台输出在.NET中,当编写一个控制台应用程序?

Is there a way to create a second console to output to in .NET when writing a console application?

推荐答案

好了,你可以开始一个新的cmd.exe进程,并使用标准输入输出和标准输出来发送和接收数据。

Well, you could start a new cmd.exe process and use stdio and stdout to send and recieve data.

ProcessStartInfo psi = new ProcessStartInfo("cmd.exe")
{
    RedirectStandardError = true,
    RedirectStandardInput = true,
    RedirectStandardOutput = true,
    UseShellExecute = false
};

Process p = Process.Start(psi);

StreamWriter sw = p.StandardInput;
StreamReader sr = p.StandardOutput;

sw.WriteLine("Hello world!");
sr.Close();

在<一个更多信息href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardinput%28vs.71%29.aspx">MSDN.

这篇关于有没有办法写一个控制台应用程序时,创建第二个控制台输出到.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆