
When a batch file is run, the shell program (usually COMMAND.COM or cmd.exe) reads the file and executes its commands, normally line-by-line. Similar to Job Control Language (JCL), DCL and other systems on mainframe and minicomputer systems, batch files were added to ease the work required for certain regular tasks by allowing the user to set up a script to automate them. The term "batch" is from batch processing, meaning "non-interactive execution", though a batch file may not process a batch of multiple data. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as IF, FOR, and GOTO labels.

It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. Note, this is a "busy" operation, which eats the CPU, and therefore I don't recommend it when you can use the WScript.Sleep procedure, but I present it as a conceptual option for the sake of completeness: set sleepSec=3 & set sleepVbs=%temp%\sleep.A batch file is a script file in DOS, OS/2 and Microsoft Windows. Here's basically the same thing, written a bit differently: set sleepMs=3000 & set sleepVbs=%temp%\sleep.vbs & echo WScript.Sleep WScript.Arguments(0) > %sleepVbs% & cscript %sleepVbs% %sleepMs% //B & del %sleepVbs%Īnd then finally, like ping, CScript itself has a timeout option! So, if you enter an infinite loop in the script, you can let the interpreter enforce the duration. echo WScript.Sleep 3000 > %temp%\sleep.vbs & cscript %temp%\sleep.vbs %sleepMs% //B & del %temp%\sleep.vbs The script does the sleeping for you (for 3 seconds in this example). Here's a one liner, to create a temp script, execute it, then delete it. Using the technique illustrated here, you can mix the two (not "seamlessly", but "functionally".).

Often VBS can do things that batch cannot, or at the very least do so with drastically more ease. The basis of this solution has all sorts of application beyond this.


After that, I agree that the ping "kludge" is perhaps the next best option, as it is very simple. But as noted in the comments, that's not always an option (e.g. Disclaimer: this is not the "ideal" solution, so don't bother beating me over the head with that like done to those recommending ping.
