There are a few ways to have a batch script wait for a number of seconds. The simplest and most widely available without any additional programs is to use the ping command.
The following is is an example... PING!
ECHO Waiting 5 seconds
PING 1.1.1.1 -n 1 -w 5000 > NUL
Comments 4 Comments • Jump to latest comment
You can also use the sleep command just like on *NIX boxes. You can get it from Microsoft Services for UNIX.
I typically use ping also, even though it's a common batch hack. These days, I prefer relying on PowerShell instead of plain batch files though.
You should use the loop back address versus a non existing ip
ECHO Waiting 5 seconds
PING 127.0.0.1 -n 1 -w 5000 > NUL
Your method for a timer is nice since it doesn't use any "Special" commands or require additional software to be loaded like powershell.
Lee Wilburn
Suzlon Wind Energy
If your question has been resolved, please click "Mark as Solution"! Thank you. Hope it helps!
I found that the syntax is different in Windows based DOS.
REM Wait 5 seconds
ping -n 5 127.0.0.1 > nul
Would you like to reply?
Login or Register to post your comment.