Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to add wait period in batch file

Posted on 2010-09-15
20
Medium Priority
?
959 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:iamdieter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
  • +3
20 Comments
 
LVL 6

Expert Comment

by:JJClements
ID: 33683208
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.
0
 

Author Comment

by:iamdieter
ID: 33683241
Will try, thanks. So there is no wait command I can use instead?
0
 

Author Comment

by:iamdieter
ID: 33683278
I am currently using the ping command: ping -n 15 localhost
This does not look good when it shows ping xxxxxx, looks unprofessional
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 7

Expert Comment

by:marektech
ID: 33683334
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.
0
 
LVL 6

Expert Comment

by:Inderjeetjaggi
ID: 33683357
You can try to use
Pause 5 seconds.
0
 
LVL 3

Expert Comment

by:Jofnn
ID: 33683423
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

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33683471
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
0
 

Author Comment

by:iamdieter
ID: 33683542
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.
0
 
LVL 3

Accepted Solution

by:
Jofnn earned 2000 total points
ID: 33683574
Hi,

You can set a variable at the start:

SET SLEEP=\\server\share\sleep.exe

Which you can call by then using %sleep% 10

*-*-*-*-*-*-*-*-*-*
On a side-note, the ping localhost works very well and users do not see the output due to the >NUL on the line.  I use it in a lot of my scripts and I've never had any issues!
0
 
LVL 3

Expert Comment

by:Jofnn
ID: 33683592
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)
0
 
LVL 7

Expert Comment

by:marektech
ID: 33683594
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 :)
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33683614
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.
0
 
LVL 7

Expert Comment

by:marektech
ID: 33683615
Try putting the sleep.exe in the same folder as the batch file.
0
 
LVL 3

Expert Comment

by:Jofnn
ID: 33683629
@dragon-IT

PING would still work if you used "localhost" though... as it's technically speaking to it's own NIC
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33683667
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.

0
 
LVL 3

Expert Comment

by:Jofnn
ID: 33683701
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.
0
 
LVL 7

Expert Comment

by:marektech
ID: 33683810
Did you go with sleep.exe in the end from www.sleepcmd.com?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33684221
Yeah, bizarre choice of answer ... did you make a mistake there?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33684225
(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!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33684244
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
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question