I use a batch file to start up a few of the programs I need running in the background. Up until now, I had used the pause command to execute it after some of the other start-ups finished. I would prefer to use the wait or sleep commands but they do not appear to be included in Windows 7.

Anybody know how to put those commands back in, or a different method that achieves the same results?

link|improve this question

75% accept rate
Or you could use powershell: stackoverflow.com/questions/1741490/… – Berzemus Nov 9 '10 at 14:34
feedback

6 Answers

up vote 13 down vote accepted

There are many sleep utilities you can download and drop into your System32 folder, one is provided with the Windows Server 2003 Resource Kit called sleep.exe.

You can also use the ping trick:

:sleep
ping 127.0.0.1 -n 2 -w 1000 > NUL
ping 127.0.0.1 -n %1 -w 1000 > NUL

then from somewhere in your batch file, you can call it like so:

CALL :sleep 1
link|improve this answer
the ping trick could be used as a temperary solution, but I would prefer one that just suspended the process, rather than have it do busy work for the time. Also, which one of the items in that list you linked was what I was looking for? – Cegorach Sep 29 '09 at 0:29
You want sleep.exe – John T Sep 29 '09 at 0:32
i tried CALL :sleep 1 from a test batch file and it responded with "system cannot find the batch label specified - SLEEP" – Cegorach Sep 29 '09 at 0:38
because you need to add the subroutine I posted above. Call just calls the subroutine, which is the 3 lines I posted above the call command. – John T Sep 29 '09 at 0:58
feedback

You can use the timeout command:

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.

For example, to wait for 10 seconds:

TIMEOUT /T 10

For more details:

TIMEOUT /?
link|improve this answer
feedback
timeout /t <seconds> /nobreak > NUL
link|improve this answer
Works great! calc && timeout 3 && notepad – Tom Wijsman Sep 1 '10 at 13:10
feedback

There is also

waitfor SomethingThatIsNeverHappening /t 10

Which will wait for between 1 and 99999 seconds.

link|improve this answer
feedback

sleep.exe is included in the Windows Server 2003 Resource Kit Tools.

You may use:

sleep /?
sleep seconds
sleep -m microseconds

link|improve this answer
feedback

If you have Python installed (and added the install path to your environment variable), you can let Python do the sleeping with something like:

echo from time import sleep; sleep(3) | python

(If you have Windows Vista or higher, timeout naturally is the way to go, though.)

link|improve this answer
feedback

protected by Ivo Flipse Dec 28 '10 at 21:36

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

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