How to Sleep or Wait X Seconds in a Bat File

Jinku Hu Feb 02, 2024
  1. Batch Sleep With timeout (> Windows 7 / 2008)
  2. Batch Wait With ping Command
How to Sleep or Wait X Seconds in a Bat File

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.


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 - could also produce the 1-second delay between each consecutive ping, and it consumes less CPU load.

ping Bat Wait Example

ping -n 6>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

Author: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn Facebook