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

后端 未结 3 1018
礼貌的吻别
礼貌的吻别 2020-12-02 21:10

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

3条回答
  •  执念已碎
    2020-12-02 21:54

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

    More info on MSDN.

提交回复
热议问题