Wait in a batch file

There maybe number of reasons why you may want to “sleep” in a batch file. Depending on your Operating System there a couple of ways to achieve this.

timeout – Windows Vista and Windows 7

In Windows Vista and Windows 7 simply use a buit-in command timeout. For example timeout /T 10 will wait 10 seconds.
timeout command in Windows 7

ping (Windows XP)

Windows XP, unfortunately doesn’t have a dedicated timout command. You can achieve very similar result by pinging localhost. You don’t have to be connected to the internet, but must have a working network adapter.
For example this command will wait approximately 10 seconds:

ping -n 11 127.0.0.1 > NULL


-n 11
– how many times to ping. ping will wait 1 second between pings, so simply put your desired timeout +1. For example -n 11 for 10 seconds; -n 26 for 25 seconds, etc.
127.0.0.1 – localhost IP address
>NULL – output to NULL (simply doesn’t display PING statistic)
ping -n 11 127.0.0.1 > NULL


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha
captcha
Reload