Tech Journal Back to Tech Journal

How can I make a Windows batch file "sleep" for a few seconds?

The simplest way is to abuse the ping command. Since ping sends 1 packet every second, you could have it pause for 5 seconds using the command:

ping -n 5 >NUL

If the computer's networking is off, then will fail and timeout, which is an indeterminate length of time. You could try and overcome this by specifying the timeout to be 1000 milliseconds (1 second), like this:

ping -n 5 -w 1000 >NUL

Just remember that specifying the timeout only affects the upper limit of time that ping will wait for a packet. You cannot use this to make ping sleep for less than a second.

Of course, there's also a sleep command in one of the Windows Resource Kits, or you could write your own.

Last updated on 2009-05-05 04:28:08 -0700, by Shalom Craimer

Back to Tech Journal