Search code examples
c#.net-6.0

How to get Process.Start to start a separate process for a console application?


I was under the impression that Process.Start() would more or less function the same as double clicking a .exe with the caveat that you can't pass cmdline parameters via double click.

So when I told my console application to start other console projects in the same solution I expected to see multiple console windows. Instead all of their text got combined into 1 window and 1 process.

This is problematic for many reasons. Separate processes have separate memory and do separate things.

Here is my code:

    Console.WriteLine("Starting Chat server");

    System.Diagnostics.Process.Start("ChatServer.exe");

    Console.WriteLine("Starting Map server");

    System.Diagnostics.Process.Start("MapServer.exe");

    Console.WriteLine("Starting Mission server");

    System.Diagnostics.Process.Start("MissionServer.exe");

    Console.WriteLine("Starting Queue server");

    System.Diagnostics.Process.Start("QueueServer.exe");

        
    while(true)
    {


    }

And here is the result:

enter image description here

However, if I go into the /bin/debug folder I can double click each .exe separately and get the expected result. enter image description here

So shouldn't there be a way to do this in C#? I'd rather not have to switch to batch or powershell just to start a bunch of console apps. Is there some code I can write to effectively do what double clicking each .exe file separately would do?


Solution

  • In order for this behavior to vanish, you should pass to your process an instance of ProcessStartInfo with UseShellExecute set to true.