batch-file


windows batch file - IF with AND condition using command-line arguments with a multi-line body [duplicate]


i am new here so i'll try to be as good as i can.
So i am trying to make a RPG based on text-based MS-DOS, and i am going pretty well as i just saw that if the user puts an invalid input at set /p, like an empty answer (just pressing enter) or an answer which is not on the "IF", the batch just crashes, and I would like to fix that so it will be less crashy.
Here is one of the parts i'd like to fix:
#echo off
title "Wasteland Adventure"
color 0A
cls
:Menu
cls
echo.
echo.
echo Welcome to Wasteland Adventure
echo.
echo To start a new game, type NEW and press ENTER.
echo To see instructions for the game, type INSTRUCTIONS and press ENTER.
echo To quit, type QUIT and press ENTER.
set input=
set /p input=What do you want to do?
if %input%==new goto INTRO
if %input%==instructions goto INSTRUCTIONS
if %input%==quit goto EXIT
Thanks in advance
it's not the set /pthat crashes, but:
if %input%==new
if %input% is empty, this is parsed as:
if ==new
obviously a syntax error. To avoid this, use:
if "%input%"=="new"
An empty input will then be parsed as:
if ""=="new"
which works fine. Complete code like this:
:Menu
set input=
set /p input=What do you want to do?
if "%input%"=="new" goto INTRO
if "%input%"=="instructions" goto INSTRUCTIONS
if "%input%"=="quit" goto EXIT
REM for any other (invalid) input:
goto :Menu

Related Links

What is wrong with this IF NOT statement?
Batch Script Specifics
Send command to an already opened .bat window from HTA/VBScript
How to check url is working in Batch
Batch script to match and zip files
searching for text file(s) and adding a line in them with batch file
batch script error - mkdir not working with fully qualified directory path
'Missing operator' in batch for statement
Batch: “If string in output” within psexec (sending command chain)
How do I get a batch file to add up numbers in a separate txt file?
Redefining the value of a variable that has been defined together with another variable
How to delete directories containing certain string using batch file in Windows?
How to echo a redirect command to a txt
How to get pid in batch for cmd with parameters?
Why does my batch script stop after activating a new conda env?
i have a script to log out disconnected users it create output file. but it alway get replace with new

Categories

HOME
sonarqube
url-redirection
fabricjs
fuelux
c++11
apache-jena
object
jmx
flex
numbers
replace
azure-container-service
32bit-64bit
little-proxy
owin
line
jsonpath
intercom
onedrive-api
cumulocity
altera
easyphp
user-experience
poedit
babel
ember-cli
hta
flask-sqlalchemy
interpreter
cart
autolisp
hreflang
joomla2.5
reactjs.net
html-encode
modalviewcontroller
xajax
apiary.io
modernizr
android-softkeyboard
naming
mesosphere
user-defined-fields
reportservice2010
tf
convex-optimization
lightning
pybrain
universal-analytics
shinobi
cvxpy
reporting-services-2012
greatest-n-per-group
pre-build-event
omniauth-facebook
query-by-example
phpwebsocket
fink
nio2
grass
cycle2
jaunt-api
rasterize
spring-retry
avisynth
xenomai
ons-api
toolkit
sony-lifelog-api
mod-proxy
viola-jones
ansi
cryptographichashfunction
nodelist
at-job
cosine-similarity
big-ip
lnk
radiant
maven-scm
android-audiorecord
xmltodict
eclipse-kepler
mysql-error-1044
code-duplication
dtmf
rolify
workitem
cascadingdropdown
chart-director
apache-abdera
joomla3.1
vfs
iboutlet
paginator
appjs
virtualpathprovider
urlrewriter
uipagecontrol
twitterizer
nhprof
ruby-1.8
updatesourcetrigger
drupal-fivestar
pos-for-.net
dsl-tools
mathematical-notation
google-wave
product-management

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile