windows - Batch file PAUSE requires two key presses to dismiss -
i have next code:
@echo off set scripttitle=mode changer title %scripttitle% rem take details set /p machine=enter machine name:%=% echo. %machine% set /p rmsnewmode=mode (t/l):%=% echo. %rmsnewmode% rem perform task cls rem check machine existence ping %machine% -n 1 if %errorlevel% == 1 call:error "the specified machine (%machine%) not located." :error color 4f title error: %scripttitle% cls echo. next error has occurred: echo. echo. %~1 echo. pause goto eof once batch file has completed, 'press key continue' expected. however, requires 'any key' pressed twice before batch file end. appears if replace next line:
if %errorlevel% == 1 call:error "the specified machine (%machine%) not located." with
if %errorlevel% == 1 goto error i prompted once.
what issue?
unlike many languages, batch has no concept of end of "procedure" - continues execution line-by-line until reaches end-of-file. consequently, need goto :eof after completing mainline, otherwise execution go on through subroutine code. :eof predefined label understood cmd mean end of file. colon required.
when call :label batch returns @ end-of-file (because label called) statement after call - color 4f within error routine. having executed pause before returning, batch charges on, line-by-line, until 1 time 1 time again encounters pause - hence 2 prompt/response cycles.
windows batch-file scripting
No comments:
Post a Comment