Is it possible to insert a timed pause in a DOS batch file?
It should act like the pause command, but instead of having to hit any key, it will continue on its own in X seconds.
Is it possible to insert a timed pause in a DOS batch file?
It should act like the pause command, but instead of having to hit any key, it will continue on its own in X seconds.
Assuming you're not talking about DOS batch files but Windows batch files:
> timeout /?
TIMEOUT [/T] timeout [/NOBREAK]
Description:
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.
Parameter List:
/T timeout Specifies the number of seconds to wait. Valid range is -1 to 99999 seconds. /NOBREAK Ignore key presses and wait specified time. /? Displays this help message.
NOTE: A timeout value of −1 means to wait indefinitely for a key press.
Examples:
TIMEOUT /? TIMEOUT /T 10 TIMEOUT /T 300 /NOBREAK TIMEOUT /T -1
The ugly, but traditional, solution that I've seen used when you don't want to install any non-stock software is to use PING. Such as:
@echo off
rem Sleep 5 seconds
ping -n 6 127.0.0.1>NUL
The 6 is necessary because the first request is returned almost immediately, counting for roughly "0" seconds, so you need to send x + 1 more requests to get the desired delay.
If you mean "batch" files. There's no built-in command; but the Win2003 Resource Pack included a program that functions the same. More info here: http://malektips.com/xp_dos_0002.html
Or, you could do it this way:
@echo off
rem Sleep 5 seconds
CALL :TIMEOUT 5
ECHO Do other stuff here
GOTO :END
:TIMEOUT
ping -n %~1 -w 1 127.0.0.1>nul
EXIT /B 0
:END
pause