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

Mat*_*ze 17 .net c# console

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

ale*_*exn 19

好吧,你可以启动一个新的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();
Run Code Online (Sandbox Code Playgroud)

有关MSDN的更多信息.

  • 哼.我无法在Windows 7 + .NET 4中使用它.想知道改变了什么...... (12认同)
  • 我也无法让这个工作.这个过程开始了,因为我可以在任务管理器中看到它,但是控制台窗口永远不会出现,无论我将ProcessStartInfo对象的`CreateNoWindow`和`WindowStyle`属性设置为什么.也许它与Windows 7的权限有关? (2认同)