I need a way to prompt a user for an input using batch

不想你离开。 提交于 2020-01-06 12:37:03

问题


I noticed a post on how to make a batch that opens another batch upon an input. However, I need a way that will make the code pause until the correct input is entered, then continue.

So for example, the code would ask what is the access code?

Then the user would input the correct code, for example 123.

Then the code would say "Welcome!" Then it would execute another question like "What do you want to do today?" There would be a list of options:

A. Game

B. Browse

C. Nevermind

The user would in put a, b, or c and the script would start either a game or web browser. If the user selected C, then it would exit.

Thanks for the help!


回答1:


@echo off

echo Welcome!
echo What do you want to do today?
echo.
echo A. Game
echo.
echo B. Browse
echo.
echo C. Nevermind
echo.

choice /C:ABC /N /M "Enter your choice:  "
if "%errorlevel%"=="1" goto :game
if "%errorlevel%"=="2" goto :browse
if "%errorlevel%"=="3" goto :nevermind
goto :error



回答2:


I think a little bit modified version of code should work just fine.

@Echo off
:Start
cls
echo Welcome !
echo To Greet press one.
echo For Goodbye press two.
echo To Abort press 3 
ECHO.
ECHO.

SET /p Option=Choice:
if "%Option%"=="1" GOTO Sub_MenuA
if "%Option%"=="2" GOTO Sub_MenuB
if "%Option%"=="3" GOTO Sub_MenuC
if "%Option%"=="quit" GOTO EOF
Goto Start

:Sub_MenuA
echo Hi There!
pause
Goto Start
:Sub_MenuB
echo tatas !
pause
Goto Start
:Sub_MenuC
echo Aborted
Pause
Goto Start
:EOF


来源:https://stackoverflow.com/questions/14942553/i-need-a-way-to-prompt-a-user-for-an-input-using-batch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!