How can I test a button click on a pause command in batch mode?

I am writing a batch script where the user reads a disclaimer, then they press any key to continue or "E" to exit. It looks something like this:

@echo off
echo (some disclaimer text here)
echo.
echo once you fully understand this message, press any key to continue, or press "E" to exit.
::I know that pause doesn't take input, I'm just using it as a placeholder for something
pause>nul
cls
echo Welcome!
pause

      

Is there a way to do this? Thank!

To clarify, I want to get out of the second, they press the E key. I've seen this before, but I forgot where he saw it.

+3


source to share


1 answer


Choice.exe

does what you describe, although it has no option for "any key". You can specify a specific key such as "Y" below.



echo once you fully understand this message, press "Y" to continue, or press "E" to exit.
choice /c ey
if errorlevel 2 goto :welcome
if errorlevel 1 goto :canceled

rem User pressed Ctrl+C

:canceled
rem User pressed E.  Do cancel stuff.
goto :eof

:welcome
rem User pressed Y.  Do welcome stuff
echo Welcome!

      

+2


source







All Articles