简体   繁体   English

从 C# WinForms 应用程序在控制台中的进程完成后暂停?

[英]Pausing after process completion in the console from a C# WinForms app?

I'm writing a WinForms application that runs a process in a new console window when a user clicks a button.我正在编写一个 WinForms 应用程序,当用户单击按钮时,该应用程序在新控制台 window 中运行一个进程。 Is there any way to get the console window to pause - waiting for a keypress - before the process exits, to allow the user to view the output onto the console?有没有办法让控制台 window 在进程退出之前暂停 - 等待按键 - 以允许用户在控制台上查看 output ? The following code runs the process in a console window, but the window disappears immediately after execution finishes:以下代码在控制台 window 中运行该过程,但 window 在执行完成后立即消失:

private void button1_Click(object sender, EventArgs e) {
    Process.Start(@"ffmpeg.exe", "--help");
}

Try using cmd like so (/k makes it not close the window)尝试像这样使用 cmd (/k 使它不关闭窗口)

private void button1_Click(object sender, EventArgs e) {
    Process.Start(@"cmd.exe", "/k ffmpeg.exe --help");
}

What I had to end up doing was invoking a .bat script that took parameters from the WinForms app to behave how I wanted, and the script finished with a @PAUSE to wait for a keypress.我最终要做的是调用一个.bat脚本,该脚本从 WinForms 应用程序中获取参数以表现我想要的行为,并且脚本以@PAUSE结束以等待按键。 Don't think there's another way to do it, annoyingly.不要认为有其他方法可以做到这一点,烦人。

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

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