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

Batch file - variable won't update when assigned a new value
Putting pairs of files into separate zip archives
Windows Batch File: Output filename without extension
Creating Conditions on Batch Files
ffmpeg working from cmd prompt but not from scheduled job
I want to get a file with endingstring.json in batch file
Read and write REG_DWORD from batch file
Corrupted zip file after sending it via ftp in command line (.bat)
Start a browser, any modern browser, from win 7 command line at a preset geometry. Is it possible
File processing via list of files in text document in batch
Keep just last 100 rows of data in text file
Extract all string from large text file Batch
Xcopy folder selection
ImageMagick cmd to vbs or bat
Can some one tell me what is wrong with this bat script?
Get formatted output for integer variable in cmd

Categories

HOME
google-app-engine
fpga
google-spreadsheet
formal-languages
zend-framework
solver
static-site
xbee
hugo
zip
crystal-reports-2013
missing-data
mvc5
opengl-3
categorical-data
drop-down-menu
gson
watson-conversation
jxl
openbugs
stellar.js
endpoint
eip
magnetic-cards
do-while
altera
microsoft-dynamics-nav
digital-signature
delphi-xe5
lilypond
qliksense
itunes
slidetoggle
fat
jackson-modules
sammy.js
reverse
slacktextviewcontroller
searchkit
raft
playframework-2.1
imagenet
xdocreport
recurrent-neural-network
laravel-elixir
datacachefactory
contract
berkeley-db-je
ntvs
builder
dbcontext
google-cse
page-replacement
modelsim
cup
css-transforms
type-theory
flac
filenet
rmongo
cudd
qtplugin
firebase-security
jclouds
stream-processing
cda
phpwebsocket
np-spring
highland.js
decimalformat
fiware-monitoring
wiredep
phonertc
zen-cart
android-launcher
amiga
sha512
omnifaces
git-ftp
bufferedinputstream
nodelist
post-commit-hook
tweenlite
nsmenu
buffering
xmltodict
windows-embedded-standard
spring-3
eclipse-kepler
http-patch
dtmf
inappsettingskit
merb
dolby-audio-api
jquery-1.9
diem
joomla-template
font-awesome-4.0.0
curb
frameworkelementfactory
patricia-trie
nokia-s40
josql
workflow-services
promotion-code
uideviceorientation
data-mapping
skype4java
windows-identity
scrubyt
software-lifecycle
application-planning
entitykey
netbeans6.1

Resources

Encrypt Message