How to pause execution for a while in a Windows batch file between a command and the next one?
The correct way to sleep in a batch file is to use the
timeout command, introduced in Windows 2000.
To wait somewhere between 29 and 30 seconds:
timeout /t 30
The timeout would get interrupted if the user hits any key; however, the command also accepts the optional switch
/nobreak, which effectively ignores anything the user may press, except an explicit
timeout /t 30 /nobreak
Additionally, if you don't want the command to print its countdown on the screen, you can redirect its output to
timeout /t 30 /nobreak > NUL
Since it applies here, too, I'll copy my answer from another site.
If you want to use ping, there is a better way. You'll want to ping an address that does not exist, so you can specify a timeout with millisecond precision. Luckily, such an address is defined in a standard (RFC 3330), and it is
192.0.2.x. This is not made-up, it really is an address with the sole purpose of not-existing (it may not be clear, but it applies even in local networks):
192.0.2.0/24 - This block is assigned as "TEST-NET" for use in documentation and example code. It is often used in conjunction with domain names example.com or example.net in vendor and protocol documentation. Addresses within this block should not appear on the public Internet.
To sleep for 123 milliseconds, use
ping 192.0.2.1 -n 1 -w 123 >nul
You can also insert a ping to localhost. This will take 4 seconds to complete (by default). It is considered a kludge by some, but works quite well all the same.
protected by Michael Hampton♦ Dec 2 '15 at 22:31
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?