Sleep command in Windows (delay)

There is no straight forward sleep command in Windows. All Unix variants provides this command to provide delay in shell scripts. I circumvent this I am using ping command as given below which provides sleep functionality with approximate accuracy. Ping command is used to check the connectivity between to machines in a network.

The below command will create 2 seconds delay. Let’s see how it works.

ping -w 1000 -n 2 1.1.1.1 > NULL

ping : Ping the specified host machine

-w timeout: Timeout in milliseconds to wait for each reply (I have selected 1000 to make unit as 1 second)

-n count: Number of echo requests to send (No.of seconds to sleep)

1.1.1.1: Dummy IP Address

> NULL: To eliminate the unwanted message

To adjust for better accuracy you can play with different values for -w argument. You can have this command in a batch file called sleep.bat and pass time in seconds as argument like this. Here is the sleep.bat

@echo off
ping -w 1000 -n %1 1.1.1.1 > NUL

Call this batchfile as “sleep 2″ for seconds and so.

Note: Windows Resource kit provides this functionality, but it involves agreeing to some license and massive download – where sleep is part of a big tool kit. It is available here.






More posts in this category


No Comments on “Sleep command in Windows (delay)”

You can track this conversation through its atom feed.

No one has commented on this entry yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

RSSSubscribe to Comments on this post



Educate Elevate!

Well said!

If you have to gain all these other "soft skills" or business skills in order to just be a regular software engineer, then why keep working for someone else? One of the main reasons for being an employee is because it's (supposed to be) both easier and safer than striking out on your own. Instead of long hours and having to wear many hats, you can just concentrate on your own skill, and leave the business stuff to the people who specialize in that. Anyone familiar with the idea of specialized labor should understand this. The downside is (supposed to be) your pay is lower than it could potentially be by owning and operating your own business. If today's corporations want their regular rank-and-file employees to wear many hats, be multi-talented, and have a lot of business skills, then they're simply not doing their own jobs correctly. - Grishnakh (Slashdot user)

Archives

Google Page Rank

Creative Commons License
Black God by KaruppuSwamy Thangaraj is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Based on a work at www.karuppuswamy.com.
Permissions beyond the scope of this license may be available here