The PAUSE Keyword in Batch Script

MD Aminul Islam May 24, 2022
The PAUSE Keyword in Batch Script

Sometimes when we run a .bat file outside the Windows CMD by double-clicking on it, it closes immediately after completing its task. This article will discuss how to stop this default action using the keyword PAUSE.

Use the PAUSE Keyword in Batch Script

PAUSE is a key of Batch Script that pauses a batch file’s execution. It displays the most common CMD message: Press any key to continue....

The execution of a running Batch Script can also be paused by pressing a combined key CTRL+S. Another keyword, BREAK, is also used for this purpose, but it works differently.

After showing the pause message, pressing any key will continue the operation. Let’s see an example to make it easier to understand.

@echo off
PAUSE

This example will show an output like the one below.

Output:

Press any key to continue...

If you don’t want to show the default message: Press any key to continue... and want to show your own message, you can follow this example.

@echo off
Echo This is the message...
PAUSE >nul

In this example, the user will see the message: This is the message... instead of Press any key to continue....

Output:

This is the message...

Basically, PAUSE is used at the end of a Batch Script. It provides some time for the user to go through some output text.

An alternative to the keyword PAUSE is to run the Batch Script using CMD /K. The general format of using this command is START CMD /K E:\DIRECTORY\Your_Script.

Let’s see an example.

@echo off
START CMD /K E:\DIRECTORY\Batch_Script.bat

As you can see, we used the CMD /K with the START command. In this way, the script will open in a window that will remain open for further user action.

The advantage of using this method is that you will be able to run the same script without editing it in unattended mode. This will also act like PAUSE.

Please note that the code we showed in this command is written in Batch and only for the Windows CMD environment.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn