Better way to wait a few seconds in a bat file? [duplicate]

Possible Duplicate:
How to sleep in a batch file?

Here's a haxxorish way to pause for a second in a batch file:

PING 400.500.600.700 > NUL

I've googled but I'm not sure there are any better ones.. any ideas? :)


You can use the "default choice" and "timeout" options of the built-in choice command to create a delay.

@echo off
echo Hi, I'm doing some stuff
echo OK, now I need to take a breather for 5 seconds...
choice /d y /t 5 > nul
echo Times up! Here I go again...

The correct way to do this is to use the timeout command, introduced in Windows 2000.

To wait 30 seconds:

timeout /t 30

The timeout would get interrupted if the user hits any key; however, the command also accepts the optional switch /nobreak, which effectively ignores anything the user may press, except an explicit CTRL-C:

timeout /t 30 /nobreak

Additionally, if you don't want the command to print its countdown on the screen, you can redirect its output to NUL:

timeout /t 30 /nobreak > NUL

@echo off
echo It is time for liftoff.
timeout /t 5
echo Commencing crash sequence.
timeout /t 5

Hitting a key will over ride the count down is the only downside.