Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent auto-closing of console after the execution of batch file

What command can I put at the end of a batch file to prevent auto-closing of the console after the execution of the file?

like image 461
joe Avatar asked Jun 12 '09 18:06

joe


People also ask

How do I keep a Command Prompt window open after a batch file?

Edit your bat file by right clicking on it and select “Edit” from the list. Your file will open in notepad. Now add “PAUSE” word at the end of your bat file. This will keep the Command Prompt window open until you do not press any key.

Why is CMD closing automatically?

If the system file is damaged, it may also cause the problem that CMD opens and closes immediately in Windows 10. For this, you can try to fix this problem by running the Windows 10 System File Checker (SFC).


2 Answers

In Windows/DOS batch files:

pause 

This prints a nice "Press any key to continue . . . " message

Or, if you don't want the "Press any key to continue . . ." message, do this instead:

pause >nul 
like image 111
Dave Bauman Avatar answered Sep 22 '22 14:09

Dave Bauman


Depends on the exact question!

Normally pause does the job within a .bat file.

If you want cmd.exe not to close to be able to remain typing, use cmd /k command at the end of the file.

like image 41
Rutger Nijlunsing Avatar answered Sep 25 '22 14:09

Rutger Nijlunsing