I'm writing a WinForms application that runs a process in a new console window when a user clicks a button. 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? The following code runs the process in a console window, but the window disappears immediately after execution finishes:
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)
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. Don't think there's another way to do it, annoyingly.
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.