Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pausing a batch file for amount of time [duplicate]

Possible Duplicates:
Sleeping in a DOS batch file
How to wait in a batch script

I have a program that is kicked off with a batch file.

The first module takes 10 seconds or so to initialize, and I want a way to "sleep" for 15 seconds before the second module is called, but I don't want it to require the user to hit a key like "pause" seems to require.

So, this is what I mean:

echo %PATH%

pause 10

echo %PATH%

In this example, I want there to be 10 seconds in between the echos. Is this possible? I've seen some examples using "ping 1.1.1.1" but it doesn't seem to work all the time correctly.

like image 386
mainstringargs Avatar asked Feb 05 '11 17:02

mainstringargs


People also ask

How do I pause a batch file for a certain amount of time?

TIMEOUT — Type timeout time where "time" is replaced by the number of seconds to delay. For example, typing in timeout 30 will delay your batch file for 30 seconds. If you want to prevent people from skipping the delay with a keypress, type in timeout time /nobreak (where "time" is the number of seconds to wait).

How do I pause a batch file in 10 seconds?

D:\>TIMEOUT /T 10 Waiting for 6 seconds, press a key to continue ... You may not always want to abort the delay with a simple key press, in which case you can use TIMEOUT 's optional /NOBREAK switch: D:\>TIMEOUT /T 10 /NOBREAK Waiting for 6 seconds, press CTRL+C to quit ...

How do you put a batch file to sleep?

The correct way to sleep in a batch file is to use the timeout command, introduced in Windows 2000.


2 Answers

ping -n 11 -w 1000 127.0.0.1 > nul

Update

Beginner's mistake. Ping doesn't wait 1000 ms before or after an request, but inbetween requests. So to wait 10 seconds, you'll have to do 11 pings to have 10 'gaps' of a second inbetween.

like image 154
GolezTrol Avatar answered Oct 05 '22 10:10

GolezTrol


If choice is available, use this:

choice /C X /T 10 /D X > nul

where /T 10 is the number of seconds to delay. Note the syntax can vary depending on your Windows version, so use CHOICE /? to be sure.

like image 23
schnaader Avatar answered Oct 05 '22 12:10

schnaader