Saturday, February 10, 2007

sleep batch for XP

Wrote this early this morning. Not sure why I never did this before, but here it is anyways. Cut and paste this into a text editor, such as notepad, and save as "sleep.bat". Call it from other batches, or run it on its own.

@echo off
rem
rem
rem this batch is intended to be called from a another batch
rem in order to wait, or sleep for a few seconds.
rem
rem CALL this batch, sleep for 5 sec, ie:
rem call sleep 5
rem or
rem call sleep
rem set pausescript=%temp%\pause10000.vbs
rem if not exist %pausescript% echo WScript.Sleep(10000)> %pausescript%
rem cscript //nologo %pausescript%
rem add an expression, just so we don't get a "missing operand" error msg
set /a SLEEP=%1 + 0
if "%1"=="" set /a SLEEP=2
if %SLEEP% GTR 99 (
@echo you must enter a number less than 100
@echo exiting...
pause
goto :EOF
) ELSE (
echo.
)
set /a SLEEPTIME=%SLEEP%000
set pausescript=%temp%\pause%SLEEPTIME%.vbs
if not exist "%pausescript%" echo WScript.Sleep(%SLEEPTIME%)> "%pausescript%"
echo Sleeping for %SLEEP% seconds...
if exist "%pausescript%" %windir%\system32\cscript.exe //nologo "%pausescript%"
goto :EOF



1 comment:

Anonymous said...

You write very well.