简体   繁体   English

防止Diagnostics.Process在完成后关闭

[英]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(); 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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Diagnostics.Process - 转储输出到文件 - Diagnostics.Process - Dump output to file 将提示输入发送到Diagnostics.Process - Send prompt input to Diagnostics.Process Diagnostics.Process的替代品,可运行简单的shell命令! - Alternatives to Diagnostics.Process to run a simple shell command! 当 Webform 应用程序从 IIS 运行时,Diagnostics.Process 启动功能不起作用 - Diagnostics.Process start function not working when webform application run from IIS PSExec:将C#控制台应用程序输出重定向到window / Diagnostics.Process? - PSExec: Redirecting C# console app output to window/Diagnostics.Process? Diagnostics.Process不使用adobe reader打开PDF文件 - Diagnostics.Process doesn't open PDF file using adobe reader 如何关闭没有引用该进程的变量的System.Diagnostics.Process - How to close a System.Diagnostics.Process with no variable referring to the process 托管后,System.diagnostics.process进程无法在IIS上运行吗? - System.diagnostics.process process is not working on IIS after hosting? 如何防止在.NET中使用Process类调用的DOS /控制台应用程序在完成后自动关闭命令提示符? - How to prevent DOS/Console application that was called using Process class in .NET, from automaticly closing the command prompt after finish? 如果我用.Kill()杀死System.Diagnostics.Process,我是否还需要调用.Close()? - If I kill a System.Diagnostics.Process with .Kill(), do I also need to call .Close()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM