Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
To impress my girlfriend. –  ToastMan Aug 9 '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 9 '10 at 19:28

4 Answers 4

up vote 3 down vote accepted

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.

share|improve this answer
    
Genius! Thank you!! –  ToastMan Aug 9 '10 at 19:52

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
share|improve this answer

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

share|improve this answer
    
If it is a batch file you can use the the choice command. To wait for 3 seconds a command like choice /t 3 /D N > nul would work. –  Zoredache Aug 9 '10 at 19:23
    
the choice command is not recognized :( –  ToastMan Aug 9 '10 at 19:26
    
You think the sleep program would work on XP if I imported it? –  ToastMan Aug 9 '10 at 19:31
    
@ToastMan, yes that program will work on Win2k to Win7. –  Chris S Aug 9 '10 at 19:43
    
The choice.exe seems to on every version of windows except XP. I think it was added as part of DOS 6.0 if I remeber right. You may be able to copy a choice.exe from a w2k box if you have one available. –  Zoredache Aug 9 '10 at 19:49

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.