"Offering free computer help, hints, and tips to the Internet populace." Now with over 3,820 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.

Return to the DOS and Batch Files page.

Print this tip


Get the Newsletter

blog comments powered by Disqus

Thanks For Sharing!



Newest Tips:

Google Chrome
[MODIFIED] Add Button to Scroll to Top of Long Web Pages
Google Gmail
Show Maps Automatically in Emails Instead of Copying and Pasting
Windows 8
Shrink the Taskbar Buttons
Sites to Browse - DVDs - Movies
[MODIFIED] Learn to Talk like Yoda

Follow Us!

About MalekTips and the Author

The MalekTips website was created in 1998 by Andrew Malek of Envision Programming. The page's goal is to freely disperse computer-related tips, hints, and informative articles. Tips are organized to be easy to find, and are presented clearly, in easy-to-understand language. MalekTips also provides information and links to public-domain, open source, freeware, shareware, and commercial software available for download.