Link to home
Start Free TrialLog in
Avatar of langlro1
langlro1Flag for United Kingdom of Great Britain and Northern Ireland

asked on

How to sleep with the option of an interrupt

Hi

I have a dos batch file that processes some commands every 20 mins.  I would like to add the option of a 'hot key' that would abort the sleep command and process the commands again.

for example
echo Press r to run now

Thanks

Rob
set sleep 20
:again
 
do some stuff here
 
set msg=   Sleeping for %sleep% Mins
   echo %msg%
call :slepLoop
 
goto again
 
 
:slepLoop
REM echo that supports surpress line feed downloaded from 
REM http://www.paulsadowski.com/WSH/cmdprogs.htm
 
%utilDir%\sleep 60
%utilDir%\echo .\c
 
set /a ctr2=ctr2+1
if %ctr2% GEQ %sleep% goto loopEnd
goto slepLoop
 
:loopEnd

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of stevenb01
stevenb01

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of langlro1

ASKER

Thanks....

By piping choice into nul, then my screen output was not messed up by choice..  :-)

see my snippet below
rem %utilDir%\sleep 60
choice /c yk /d y /t 2 /n > nul
if %errorlevel% EQU 60 set ctr2=%sleep%
%utilDir%\echo .\c

Open in new window