Link to home
Start Free TrialLog in
Avatar of iamdieter
iamdieterFlag for South Africa

asked on

How to add wait period in batch file

Hi

How do I add a waiting period of 10sec in my batch file? I want the batch file to execute the first line, then wait 10seconds before moving to the next line.
Avatar of JJClements
JJClements
Flag of United Kingdom of Great Britain and Northern Ireland image

I think the easiest way is to grab the server 2003 resource kit and use sleep.exe:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

You can use it to make the batch file sleep for x number of seconds.
Avatar of iamdieter

ASKER

Will try, thanks. So there is no wait command I can use instead?
I am currently using the ping command: ping -n 15 localhost
This does not look good when it shows ping xxxxxx, looks unprofessional
SleepCMD is free and easy.

Download it from http://www.sleepcmd.com

To test create a bat file and use the following:

sleep 10
pause

Once the 10 seconds is up you will have to hit a key. Just tested it for you and it all works great.
You can try to use
Pause 5 seconds.
Hi,

No need to download anything for this, you can achieve it by simply pinging the localhost for a bit... change the number to suit your needs :)

Jonathon

@ping.exe localhost -n 10 >NUL

Open in new window

Avatar of Steve Knight
You can use PING... just hide the output:

ping -n 11 127.0.0.1 >nul 2>&1

http://scripts.dragon-it.co.uk/links/batch-delay?OpenDocument


Steve
Sleep not working. I'm running the batch file from a shared drive on the server. Do I need to tell the batch where sleep.exe is installed?

I do not want to use PING.
ASKER CERTIFIED SOLUTION
Avatar of Jofnn
Jofnn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also - yes, you will need to tell it where to look as it will start to look where the script currently is... along with the Sys32 folder!  (hence why it would be better to set a variable at the start)
If you go down the sleepCMD route I outlined above you can also hide the sleep output with the following command:

sleep 10 /quiet

Hope this helps iamdieter :)
Only issue with PING is when there is no interface up and running, i.e. in a standalone machine with no network, wireless or other connection. Otherwise works fine, use -n wih number of secs + 1 since it does one ping then waits a sec then the second etc.
Try putting the sleep.exe in the same folder as the batch file.
@dragon-IT

PING would still work if you used "localhost" though... as it's technically speaking to it's own NIC
Nope, not if there is nothing connected to it.  I use 127.0.0.1 which is the same as localhost as long as the entry is in your hosts table but if you have no interface up, i.e. no cable connected, no wireless or 3G connection up then there is no 127.0.0.1 and it may fail.

We have a couple of standalones here, which have BAT files running on them (cleanup duties etc) and we use the command...

If there's no interfaces etc, the localhost then defaults back to the MAC of the NIC.
Did you go with sleep.exe in the end from www.sleepcmd.com?
Yeah, bizarre choice of answer ... did you make a mistake there?
(Not that there is anything wrong with it I mean, just not crediting the other people who suggested it before your addition on that one!
Hmm, I see your comment now re: "I do not want to use PING."  .. your choice I suppose.... actually that is another way:

choice /T 10 >NUL