2

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.

Alex Angas
  • 2,017
  • 2
  • 26
  • 37
ToastMan
  • 544
  • 4
  • 18
  • 29
  • To impress my girlfriend. – ToastMan Aug 09 '10 at 19:24
  • But seriously, I want to exceute shudown -r after a bunch of scripts have finished executing, don't ask why, and don't ask why I am not using shutdown -r -t X, it doesn't work for our purpose. – ToastMan Aug 09 '10 at 19:28

4 Answers4

6

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
Joey
  • 1,853
  • 11
  • 13
5

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.

Evan Anderson
  • 141,881
  • 20
  • 196
  • 331
1

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

Chris S
  • 77,945
  • 11
  • 124
  • 216
0

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
djangofan
  • 4,182
  • 10
  • 46
  • 59