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

Is it possible to create a batch file that will call another batch file at some point and also supply it with a sequence of inputs
GOTO was unexpected at this time
Copy files & folders from a network location using a text file containing the directories
DOS xcopy command to move files that have been restored ending with (1)
CMD-Batch File Simple Random
Batch file increment folder number
Execution of exe files one completion then execute other
Batch file - Pick a card
i don't have winzip or other tools to compress . I want to use compress with forfiles command in batch file . How to use it and rename . I
Encountering erros when trying to automate PSFTP command using a .bat file
Batch script: Parsing text gives totally unexpected output, variable value missing
Simple batchscript breaks when drag&drop a file with an underscore in its filename
Rotate textfile upside down with batch
Surpressing windows command line PAUSE command
bat file to backup folder files only if changed increment name
Append ddmmyy and update Date Modified

Categories

HOME
uml
oracle12c
deep-learning
spark-streaming
nunit
pascal
jelastic
devise
newrelic
boto3
nfs
p2p
little-proxy
ibeacon-android
xcodebuild
intercom
symmetricds
symbol
standards
mathprog
template-engine
springfox
angular-routing
interbase
fat
angularjs-components
android-maps
progress-bar
underscore.js
browser-sync
record
left-join
testbed
r-grid
erb
clickjacking
hard-drive
gnat-gps
navigator
sharepoint-workflow
openerp-7
magento-1.9.2.4
filesystemwatcher
recurrent-neural-network
c9.io
ogc
resolution
odoo-website
movilizer
clarifai
facebook-pixel
lightning
remedy
colorbar
android-testing
android-instrumentation
renaming
docpad
redistributable
windows-azure-queues
installshield-2010
bizagi
upx
invoke-sqlcmd
httpruntime.cache
tfs-workitem
themoviedb-api
dllimport
finalbuilder
teamcity-9.1
jquery-forms-plugin
rapidsvn
nodelist
primitive-types
sip-server
post-commit-hook
appserver
entry-point
paw
template-deduction
ora-00904
grails-plugin-rabbitmq
jquery-slider
vsx
drupal-nodes
git-repo
xmltodict
c++builder-xe5
argouml
midlet
sentestingkit
jquery-blockui
os.system
adobe-media-server
wiimote
google-maps-mobile
flex-mobile
screen-size
presentation-layer
duplex
fdf
flvplayback

Resources

Encrypt Message