computer help index
 
 
Search:
"Offering free computer help, hints, and tips to the Internet populace." Now with over 3,360 tips!

DOS and Batch Files

Implementing the WAIT Command in a Batch File

SUMMARY: Make your batch files wait or sleep for a specified number of seconds before continuing. Works in DOS and Windows.

Do you need a batch file that waits a certain amount of seconds? In some languages, the command would be WAIT, but DOS and Windows do not come with this command for batch files. If you want to implement the WAIT command:

For DOS, Windows 95, and Windows 98 machines

Create the following batch file and name it WAIT.BAT.

@CHOICE /T:N,%1% > NUL

Now, in order to wait 10 seconds in a batch file, just call the WAIT.BAT batch file as follows:

CALL WAIT 10

For Windows 95, Windows 98, Windows NT, Windows 2000, Windows XP, or Windows 2003 machines

You can use the following WAIT.BAT, as the CHOICE command is not included in the default install on Windows NT, Windows 2000, Windows XP, or Windows 2003:

@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n %1% -w 1000> nul

The reason for the two lines is that in order to wait using the PING command, you must add extra pings to correctly wait the desired number of seconds. Also, since the PING command is being used, it is possible that this WAIT batch file may run over a few milliseconds. Thus, it is not recommended to use this for critical real-time processing.

Windows XP and Windows 2003 machines

Since Windows XP and 2003 users do not have the CHOICE command, if you find the PING alternative not to your liking, the Windows 2003 Resource Kit has a batch file SLEEP command.

 

 
Add: Del.icio.us | Digg | Furl | My Yahoo!
 

Discuss This Tip

Print This Tip

Get E-Mail When New Tips are Online

Return to the DOS and Batch Files page.


More in MalekTips:
Internet Explorer 7 MiscWindows Vista - ExplorerGoogle Image Search



Change Cache SizeCopy File or Folder Path to DOS Prompt or Windows AppSearch for Images in Various Sizes

RSS Feeds - Subscribe!
 

You want the latest tech tips and tricks in your e-mail Inbox - FREE? Type your e-mail address below and click 'Subscribe'.
 



( sample / details ) ( opt-out instructions )
 


 Free Offer! - Subscribe to the MalekTips computer help list and be one of the first to get new computer tips, articles, and download links! ( privacy policy )  ( opt-out instructions )
This page and its contents are copyright
©1997 - 2008 Envision Programming. ( copyright/disclaimer )

Home | Free Computer Help Newsletter! | Windows | Web Development | DOS and Batch Files | Removing Spyware
Digital Camera and Photography | Computer and Internet | Software | Microsoft Word
Computer Articles | About | Contribute a Tip | Link To Us! | Computer and Technology Links
RSS Feeds |  Contact Us | Advertising | Privacy Policy | Computer Help Forums