Stop CMD from closing: batch file, Windows 10/11

Stop CMD from closing: batch file, Windows 10/11

If you have noticed that your command prompt often automatically shuts down, you may find this annoying or even worrisome. This FAQ will show you how to prevent this from happening.

Often the command prompt closes after executing a batch file that is run to execute multiple sets of commands at once. We will show you two ways to prevent this.

Adding cmd /k

Right-click on the batch file and choose Show more options at the buttom of the menu. Tap on Edit, and your default text editor will open. Now write cmd /k at the end of the batch script file. 

 cmd /K

On the top menu, open the File option and click on Save. Then, if you  run the batch file, the command prompt window will not close.

Adding "pause" to the batch script file

Open the folder containing the batch file, right-click on the batch file > Show more options.

Click Edit on top of the context menu in order to open the batch file in your default text editor.

Write pause at the end of the script.

 pause

Now press CTRL + S in order to save the changes.  

Now right-click on the batch file and run it tapping on Open command. This way the command prompt window will mantain open after execution of the batch file. 

Need more help with Windows? Check out our forum!
Around the same subject

Windows