Tuesday, October 20, 2009

Pauses and Delays in Batch Scripts

In some cases you need to wait for a certain time after calling an application from your batch file. For example, it's useful when this application must finish its work. How can one include delay in his batch script? There are several different solutions.
  1. The first way is the simplest one. You can just include "pause" command in your script. This way has a really big drawback: this command requires a key pressing to continue the execution. So this command cannot be used in pure automated scripts, because you must ask someone to press a key.
  2. The second way is to use ping command. Of course, this command is not designed for adding delays to the batch files, but it's really handy to use it in this case. The following code will make delay for ten seconds: ping -n 11 -w 1000 127.0.0.1 > nul
  3. You can use 'Sleep' utility from Windows Resource Kit. Its usage will look like sleep 10.
I'd better use the second variant because it's quite simple and will run on all versions of Windows without any external tools.

No comments:

Post a Comment

Translate