简体   繁体   中英

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:

在此处输入图像描述

However, if I go into the /bin/debug folder I can double click each.exe separately and get the expected result. 在此处输入图像描述

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM