Possible Duplicates:
Sleeping in a DOS batch file
How to wait in a batch script
I have a program that is kicked off with a batch file.
The first module takes 10 seconds or so to initialize, and I want a way to "sleep" for 15 seconds before the second module is called, but I don't want it to require the user to hit a key like "pause" seems to require.
So, this is what I mean:
echo %PATH%
pause 10
echo %PATH%
In this example, I want there to be 10 seconds in between the echos. Is this possible? I've seen some examples using "ping 1.1.1.1" but it doesn't seem to work all the time correctly.
TIMEOUT — Type timeout time where "time" is replaced by the number of seconds to delay. For example, typing in timeout 30 will delay your batch file for 30 seconds. If you want to prevent people from skipping the delay with a keypress, type in timeout time /nobreak (where "time" is the number of seconds to wait).
D:\>TIMEOUT /T 10 Waiting for 6 seconds, press a key to continue ... You may not always want to abort the delay with a simple key press, in which case you can use TIMEOUT 's optional /NOBREAK switch: D:\>TIMEOUT /T 10 /NOBREAK Waiting for 6 seconds, press CTRL+C to quit ...
The correct way to sleep in a batch file is to use the timeout command, introduced in Windows 2000.
ping -n 11 -w 1000 127.0.0.1 > nul
Update
Beginner's mistake. Ping doesn't wait 1000 ms before or after an request, but inbetween requests. So to wait 10 seconds, you'll have to do 11 pings to have 10 'gaps' of a second inbetween.
If choice
is available, use this:
choice /C X /T 10 /D X > nul
where /T 10
is the number of seconds to delay.
Note the syntax can vary depending on your Windows version, so use CHOICE /?
to be sure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With