How do I make a batch file wait / sleep for some seconds?
I use a batch file to start up a few of the programs I need running in the background. Up until now, I had used the pause command to execute it after some of the other start-ups finished. I would prefer to use the wait or sleep commands but they do not appear to be included in Windows 7.
Anybody know how to put those commands back in, or a different method that achieves the same results?
Solution 1:
There are many sleep utilities you can download and drop into your System32 folder, one is provided with the Windows Server 2003 Resource Kit called sleep.exe
.
You can also use the ping trick:
:sleep
ping 127.0.0.1 -n 2 -w 1000 > NUL
ping 127.0.0.1 -n %1 -w 1000 > NUL
then from somewhere in your batch file, you can call it like so:
CALL :sleep 1
Solution 2:
You can use the timeout
command:
This utility accepts a timeout parameter to wait for the specified time period (in seconds) or until any key is pressed. It also accepts a parameter to ignore the key press.
For example, to wait for 10 seconds:
TIMEOUT /T 10
For more details:
TIMEOUT /?
Solution 3:
timeout /t <seconds> /nobreak > NUL
Solution 4:
There is also
waitfor SomethingThatIsNeverHappening /t 10
Which will wait for between 1 and 99999 seconds.