Sunday, November 27

How to sleep in DOS batch program

In a DOS batch program, I want to have it sleep for a while before next step. For example, after starting the Apache server, I want to wait for 5 seconds until it's fully loaded, then do the next step.

By searching in the net, I found that Windows 2000 Extension Toolkit provides a sleep.exe program. But I don't have it right now.

Good, in a blog, FlyingBird gave a solution:
wscript.sleep 6000
using WSH. I want to make it flexible, that means it should be able to accept parameters to decide how long it will sleep. Finally I changed the program as:

'cscript "d:\program files\sleep.vbs" 10
' sleep program in DOS batch.
' Ben @

Set Args = WScript.Arguments
wscript.sleep Args(0)*1000

Save this to d:\program files\sleep.vbs, then in your DOS batch program, you can call it by:

cscript "d:\program files\sleep.vbs" 10 or how long you want it to sleep.

Like me, if you don't want to display anything by calling this method, you can use
cscript "d:\program files\sleep.vbs" 10 >NUL



At November 27, 2005 3:46 PM, Blogger xls said...

is the command "choice /N /T:0,10" do the same thing?

wait for 10 seconds for a default choice (y/n).

At November 27, 2005 3:48 PM, Blogger Unknown said...

'choice' is not recognized as an internal or external command,
operable program or batch file.

Is is a DOS command or a vbs program?

At November 27, 2005 8:18 PM, Blogger xls said...

oh, the old "choice" command was out of winxp.

That sucks.

At March 16, 2008 10:11 AM, Anonymous Anonymous said...

First of all a .bat file is not a program and batch is not a programming language. Also im assuming your using Windows XP, it doesn't use DOS, it uses a mimic of it, After 98 DOS was completly removed from the Windows Project

At March 16, 2008 9:25 PM, Blogger Unknown said...

Anonymous: If you think batch is not a programming language, do you think shell (sh, ksh, csh) is a programming language? How about perl script? Java script? python script?

You are right, "pure DOS" is vanished after Win98. People still talk about "DOS command line", "DOS batch", because of the history :)


<< Home