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?
To avoid this manual input, use the command "echo Y | del /P " in your batch script to answer the prompt. You can try this echo command to pass input (ex: answer for username and password prompts) to your console application, when it is invoked through batch script.
You simply substitute the parameter for 1 (e.g., %~f2 for the second parameter's fully qualified path name). The %0 parameter in a batch file holds information about the file when it runs and indicates which command extensions you can use with the file (e.g., %~dp0 gives the batch file's drive and path).
To have a batch file stop and prompt for input, you would want to look into using set /p , which will prompt for input and then assign that input to a variable. e.g.: set /P name="What Is Your Name? " echo Hello %name%!
If the input is, say, N
, your IF lines evaluate like this:
If N=="y" goto yes If N=="n" goto no …
That is, you are comparing N
with "y"
, then "n"
etc. including "N"
. You are never going to get a match unless the user somehow decides to input "N"
or "y"
(i.e. either of the four characters, but enclosed in double quotes).
So you need either to remove "
from around y
, n
, Y
and N
or put them around %INPUT%
in your conditional statements. I would recommend the latter, because that way you would be escaping at least some of the characters that have special meaning in batch scripts (if the user managed to type them in). So, this is what you should get:
If "%INPUT%"=="y" goto yes If "%INPUT%"=="n" goto no If "%INPUT%"=="Y" goto yes If "%INPUT%"=="N" goto no
By the way, you could reduce the number of conditions by applying the /I
switch to the IF
statement, like this:
If /I "%INPUT%"=="y" goto yes If /I "%INPUT%"=="n" goto no
The /I
switch makes the comparisons case-insensitive, and so you don't need separate checks for different-case strings.
One other issue is that, after the development mode command is executed, there's no jumping over the other command, and so, if the user agrees to run Java in the development mode, he'll get it run both in the development mode and the non-development mode. So maybe you need to add something like this to your script:
... :yes java -jar lib/RSBot-4030.jar -dev echo Starting RSbot in developer mode goto cont :no java -jar lib/RSBot-4030.jar echo Starting RSbot in regular mode :cont pause
Finally, to address the issue of processing incorrect input, you could simply add another (unconditional) goto
command just after the conditional statements, just before the yes
label, namely goto Ask
, to return to the beginning of your script where the prompt is displayed and the input is requested, or you could also add another ECHO command before the jump, explaining that the input was incorrect, something like this:
@echo off :Ask echo Would you like to use developer mode?(Y/N) set INPUT= set /P INPUT=Type input: %=% If /I "%INPUT%"=="y" goto yes If /I "%INPUT%"=="n" goto no echo Incorrect input & goto Ask :yes ...
Note: Some of the issues mentioned here have also been addressed by @xmjx in their answer, which I fully acknowledge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With