简体   繁体   中英

Prevent Diagnostics.Process to close after finish

I am running prompt commands using this function:

public static void Execute(string command)
{
    ProcessStartInfo psi = new ProcessStartInfo
    {
        FileName = "cmd.exe",
        Arguments = "/c " + command,
    };

     using (Process proc = Process.Start(psi))
        proc.WaitForExit();
}

But when the process ends i have no way to see the result of it in the console because it closes instantly. Is there a way to prevent this from happening?

Put Console.ReadKey(); at the end of the code:

static void Main(string[] args)
{
    ProcessStartInfo psi = new ProcessStartInfo
    {
        FileName = "cmd.exe",
        Arguments = "/c ",
    };

    using (Process proc = Process.Start(psi))
        proc.WaitForExit();

    Console.ReadKey();
}

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