dos batch sleep

23 Jun

slow down a batch file

“Gustav Medler” wrote in message
> Hello,
> is there a program anywhere which stopps executing of batch files for 1
> or 2 seconds without need to touch the keyboard?

> PAUSE requires a keyboard stroke…. batch needs user’s attention….

There are four main options for delays in Batch scripts:

1) Use the time-delay built into CHOICE command

This can be used for delays from 1-99 seconds. For example,
this command line delays 10 seconds before resuming. Change
the 10 to a number from 1-99 for other delay periods.

:: Delay script execution for 10 seconds
REM | choice /c:delay /td,10>NUL

2) Use the built-in delay mechanism of the PING command.

Assuming you have Microsoft TCP/IP installed, you can PING
the LocalHost and obtain delays in this way. With PING, you
need to specify a number equal to 1 second longer than you
want the delay to be. Unlike CHOICE delays, PING delays are
not limited to 99 seconds, however.

:: Delay script execution for 10 (= 11-1) seconds
ping -n 11 127.0.0.1>NUL

3) The free Microsoft SLEEP.EXE command

Microsoft provide a free SLEEP utility as part of the free
Windows 98 Resource Kit Batch tools. With the SLEEP.EXE
executable placed in the system path, for example in the folder
C:\WINDOWS\COMMAND, the delay syntax is simple:

:: Delay script execution for 10 seconds
sleep 10

Download Microsoft SLEEP.EXE Batch tool free from:
ftp://ftp.microsoft.com/Services/TechNet/samples/ps/win98/reskit/scrp…
and click on the filename SLEEP.EXE

4) Using the START command
Sometimes, a delay is wanted merely to allow a GUI process to finish.
In these cases the START command is useful. The command line:

start /w “C:\program files\SomeProgram.exe”

will run the program SomeProgram.exe in a separate process and /w=Wait
for it to complete before continuing. Use “quotes” around any file
specification that contains [Space]s. For brief help with START type:
start /?

======

Notes:
(a) Although the CHOICE delay method is useful to know, CHOICE
delays are very CPU intensive. Typically, CHOICE uses up all
the spare CPU time available during the delay (although it isn’t
performing any useful task). The PING version of the delay uses
typically under 0.5% of CPU capacity, and will often record a
negligible CPU usage on fast systems. So for other than trivial
delays, PING is most definitely to be preferred. Delays using
the SLEEP command use negligible CPU time.

(b) To study CPU usage of tasks such as the CHOICE, PING,
or SLEEP delay techniques, you can use the free Microsoft
process viewer WinTop:

To install WinTop, get the free download from page:
http://www.microsoft.com/windows95/downloads/default.asp
scroll down the page, and locate the item: Windows 95 Kernel Toys
Click on that and click the DownLoad Now button on the next
page. Run the packed executable: w95krnltoys.exe, in a temporary
folder, and when it unpacks, right click on WinTop.inf, and click
install. After a few moments, you can remove the contents of the
temporary folder. Place a link to C:\Windows\Wintop.exe on the
desktop to run WinTop. To terminate a process with WinTop, right
click on the process, click Properties, Priority tab, click
Terminate Process Now. WinTop has a small database of “essential”
OS components (they show with a small cog icon) which it won’t
terminate (for example mmtask). The Win95 Kernel Toys package is
suitable for Win98 (and ME as far as I am aware).

(c) Windows 95/98/ME START command features:
START is an external command: executable file START.EXE
(For brief help with START, type the command: start /? )

(i) start /w Program.EXE /Any /Switches
This runs Program.EXE in a separate process thread, and Waits(/w)
for it to complete before continuing. If Program.EXE returns an
informative ERRORLEVEL, START (with /w) returns that ERRORLEVEL
to the parent Batch file.

(ii) start Program.EXE
As /w, but doesn’t wait for Program.EXE to complete, nor does it
return an informative ERRORLEVEL from Program.EXE

Window control for the STARTed process is provided through the
/m(=run in Minimized window) /max(=run in MAXimised window) and
/r(=run in Restored window).

(iii) start DATAFILE.EXT
Opens DATAFILE.EXT in the application registered in the CLASSES_ROOT
section of the Registry to handle files of that type. For example:
(a) start http://www.website.com/index.htm
opens that page in your default Web browser.
(b) start textfile.txt
opens that file in your default Text editor (usually NotePad).

(iv) Native ERRORLEVELs from START
start /?>NUL
This command line returns ERRORLEVEL 255 if used in the Windows GUI
(protected mode), and ERRORLEVEL 1 if used in real-mode.

(v) Separate START command line parameters with [Space]s
When using START, always use [Space]s to separate its command line
elements, so for example, although, without START:
choice/c:yn
is valid syntax, with START, you must insert a [Space] before /c:
start choice /c:yn

Note: Windows 2000
In Windows 2000 and similar OSes, START is an internal command.
Use start /? in Windows 2000 for details of the extensive extra
features available (including process priority control).


(pp) William Allen