c# - 在编写控制台应用程序时,有没有办法创建第二个控制台以在 .NET 中输出?

标签 c# .net console

在编写控制台应用程序时,是否可以创建第二个控制台以输出到 .NET 中?

最佳答案

那么,您可以启动一个新的 cmd.exe 进程并使用 stdio 和 stdout 发送和接收数据。

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();

有关 MSDN 的更多信息.

关于c# - 在编写控制台应用程序时,有没有办法创建第二个控制台以在 .NET 中输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/697227/

相关文章:

c# - 异步/等待异常处理模式

c# - 如何拆分保留整个单词的字符串?

c# - 在 .NET 中操作 Excel xls 和 xlsx

c# - 如何使用 3 includes 优化 Entity Framework 查询

c# - Linq 中的字节转换

c# - AutoMapper DynamicMap 对象与匿名类型

python - 在 python 的控制台窗口上按下鼠标

java - 如何设置 for 循环计数从 1 而不是 0 开始?

python - 为什么控制台记录器与打印不同步?

c# - 如何转换字符串数据:audio/ogg;base64 to file wav in C#