Pause a batch file

Table of contents:

Pause a batch file
Pause a batch file
Anonim

Do you want to pause an action of a batch file? You can program your batch file to indicate to the user when he or she is ready to continue, or you can set your batch file to wait a certain amount of time before continuing automatically. The method you choose will depend on what your program needs and the capabilities of your system.

Steps

Method 1 of 4: Pause

669935 1 1

Step 1. Use the PAUSE command to make the program wait for the user

Pausing will continue forever until the user chooses to continue. If you want to stop running the program for a specific time, check out one of the following methods.

669935 2 1

Step 2. Place the PAUSE command where you want the program to pause

The user will be prompted to continue.

669935 3 1

Step 3. Hide the dialog box from PAUSE

You can add >zero to the end of the PAUSE command to hide the text that would otherwise be shown to the user.

Method 2 of 4: Timeout

669935 4 1

Step 1. Use the TIMEOUT command to make the program wait for a specified time

The user can skip this period or you can add a parameter to prevent the user from skipping this.

TIMEOUT may not work on older systems. If the TIMEOUT command doesn't work, see the next section

669935 5 1

Step 2. Place the TIMEOUT command where you want the program to pause

Add the flag /t followed by the number of seconds.

669935 6 1

Step 3. Prevent the user from skipping the break

Add the /nobreak flag to the possible entry to avoid skipping the break.

The user can still end the program by pressing Ctrl + C and then quit the program

Method 3 of 4: Sleep

669935 7 1

Step 1. Use the SLEEP command to make the program wait a certain number of seconds

The use of SLEEP is deprecated and has largely been replaced by TIMEOUT.

669935 8 1

Step 2. Place the SLEEP command where you want the program to pause

After the SLEEP command, add the number of seconds that the program should wait. The SLEEP command cannot be interrupted by the user.

Method 4 of 4: Ping

669935 9 1

Step 1. Use the PING command to force the program to wait a certain number of seconds

You can hide the output from the user to mask the delay. You must ping an invalid IP address or the delay timing will not work correctly. You will need to ping a valid host name, otherwise the error message will be displayed to the user.

669935 10

Step 2. Insert the PING command where you want the program to pause

The parameter >zero prevents the command from being displayed. The -n 1 parameter adds a second ping to the original command. The pause between the first and second ping, denoted by -w 30000, is the delay. The delay must be specified in milliseconds.

Popular by topic