How do I request and receive user input in a .bat

2019-01-31 03:04发布

This is what I have so far

@echo off
:Ask
echo Would you like to use developer mode?(Y/N)
set INPUT=
set /P INPUT=Type input: %=%
If %INPUT%=="y" goto yes 
If %INPUT%=="n" goto no
If %INPUT%=="Y" goto yes
If %INPUT%=="N" goto no
:yes
java -jar lib/RSBot-4030.jar -dev
echo Starting RSbot in developer mode
:no
java -jar lib/RSBot-4030.jar
echo Starting RSbot in regular mode
pause

Either way if the user enters y or n it always runs in -dev mode.

How do I make it run in -dev mode if the answer is yes, and regular mode if the answer is no. Also, how do I make it ask again if the input isn't Y, N, y, or n?

8条回答
一夜七次
2楼-- · 2019-01-31 03:59

try this for comparision

if "%INPUT%"=="y"...
查看更多
Evening l夕情丶
3楼-- · 2019-01-31 04:01
echo off
setlocal
SET AREYOUSURE = N
:PROMPT
set /P AREYOUSURE=Update Release Files (Y/N)?
if /I %AREYOUSURE% NEQ Y GOTO END
set /P AREYOUSURE=Are You Sure you want to Update Release Files (Y/N)?
if /I %AREYOUSURE% NEQ Y GOTO END

echo Copying New Files

:END

This is code I use regularly. I have noticed in the examples in this blog that quotes are used. If the test line is changed to use quotes the test is invalid.

if /I %AREYOUSURE% NEQ "Y" GOTO END

I have tested on XP, Vista, Win7 and Win8. All fail when quotes are used.

查看更多
登录 后发表回答