Sleep or Wait X Seconds in a Bat File

  1. Batch Sleep With timeout (> Windows 7 / 2008)
  2. Batch Wait With ping Command

This article will introduce how to sleep or wait x seconds in a bat file. Bat file execution pauses x seconds and then continues with the next commands.

Batch Sleep With timeout (> Windows 7 / 2008)

timetout delays the execution for the given seconds.

Syntax

timeout <seconds> /nobreak

<seconds> is any value between -1 and 100000. -1 causes the computer to wait indefinitely until a keystroke.

/nobreak ignores user keystrokes and the waiting could not be disturbed by any keystroke.

timeout Bat Sleep Example

timeout /t 5

It will pause 5 seconds before the next execution.

batch timeout example

Batch Wait With ping Command

Although PC pauses the command execution for x seconds when you use timeout command, it still consumes quite a lot of the CPU load. ping command with a loopback address - 127.0.0.1 could also produce the 1-second delay between each consecutive ping, and it consumes less CPU load.

ping Bat Wait Example

ping -n 6 127.0.0.1>nul

6 means the delay is set to 6-1=5 seconds.

>nul pipes the standard-output stream to null and therefore there is no information displayed in the console.

ping dealy example

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.