Multiple Consoles in a Single Console Application

前提是你 提交于 2019-12-03 13:03:04

Here's a quick example of what can be done... obviously, adjust paths to your liking and there are a few other ways:

Preview:

Code:

using (var process1 = new Process())
{
    process1.StartInfo.FileName = @"..\..\..\ConsoleApp1\bin\Debug\ConsoleApp1.exe";
    process1.Start();
}

using (var process2 = new Process())
{
    process2.StartInfo.FileName = @"..\..\..\ConsoleApp2\bin\Debug\ConsoleApp2.exe";
    process2.Start();
}

Console.WriteLine("MainApp");
Console.ReadKey();

This was a quick setup and many things can be and should be adjusted (exception handling, etc., etc., etc.). It should get you started, though.

You can start another process using the Process.Start() call. Take a look here for examples

Yes you can.

ProcessStartInfo allows you to capture console output.

You're probably looking for this: Redirect standard output. Note you should also redirect standard error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!