Aug 18 2006

Batch Sleep

Jeffrey Larson

I’ve written a fair number of batch scripts in my day. Useful for fairly simple to moderately simple tasks in Windows, batch scripting usually works without any extras required.

I just found a trick that allows a script to have delay time between executed statements, without needing extra .exe’s. It uses the ping command which is found on every windows operating system.

@ECHO OFF
SETLOCAL

ECHO.Closing in 5 Seconds
ECHO .....
CALL :sleep 1
ECHO ....
CALL :sleep 1
ECHO ...
CALL :sleep 1
ECHO ..
CALL :sleep 1
ECHO .
CALL :sleep 1
ENDLOCAL
GOTO :EOF

:sleep
:: sleep for x number of seconds
ping 127.0.0.1 -n 2 -w 1000 > NUL
ping 127.0.0.1 -n %1 -w 1000 > NUL
GOTO :EOF

Hope you find this handy!