13

I have created a C# Project which has multiple console applications in it. Now my question is: Is it possible to display multiple consoles when I run one application? if yes, how?

Lets say, I have a Test Application, which is the main application. I have another two Console applications say, ABC and XYZ. Now, when i run the Test Application, the console of both applications ABC and XYZ should appear.

I have written the following code:

Console.WriteLine("\n\t Calling EXE...");
Process myProcess = new Process();
string Exepath = System.IO.Directory.GetCurrentDirectory() + "\\exe\\ABCApplication.exe";
try
{
    myProcess.StartInfo.UseShellExecute = false;
    myProcess.StartInfo.FileName = Exepath;
    myProcess.StartInfo.CreateNoWindow = false;
    myProcess.Start();
}

catch (Exception ex)
{
    CreateLogFile();
}
B.K.
  • 9,982
  • 10
  • 73
  • 105
Harsh
  • 173
  • 1
  • 3
  • 11

3 Answers3

11

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

Preview:

enter image description here

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.

B.K.
  • 9,982
  • 10
  • 73
  • 105
  • @B.K. wow, what program did you use to create that video clip? – Carlo Luther Oct 31 '15 at 15:02
  • @Luther There are many screen capturing apps that create gifs. I use LICEcap (http://www.cockos.com/licecap/), Screen To Gif (https://screentogif.codeplex.com/) and Gyazo (https://gyazo.com/). Each has pros and cons. – B.K. Oct 31 '15 at 21:08
  • 2
    I believe you can open any executable this way. I mistakenly copied the wrong path and it opened a console and a WindowsForms App. This was more than useful. Many thanks. – Tanatos Daniel Aug 02 '17 at 16:19
1

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

Thomas
  • 1,563
  • 3
  • 17
  • 37
0

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.

atlaste
  • 30,418
  • 3
  • 57
  • 87