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

How to pass multiple parameters in CMD to batch file
Setting a variable from a text file
BAT Shutdown with countdown delay
Batch file: command TYPE path
batch script find and write?
Batch Program to Start Windows Audio in Safe Mode
How to pass file as an argument in a batch program
Direct the command to a newly opened separate command prompt using bat file
If statement in command line loop for windows 7 bat file
Can I use Microsoft Visual Studio 2012 to make a GUI for a batch file?
Batch File not kicking off another batch file
Filter csv files and create a new set of .csv files with the data
C opy file3.txt to f older down level three, file4.txt to four
copy certain files using batch script with whitelist txt file
Batch Script to execute a file with a variable Name
How to Extract the file name from a full path in bat?

Categories

HOME
algorithm
spark-streaming
ng-idle
apache-jena
webdriver
google-spreadsheet
jax-rs
ns-3
angular2-material
ms-access-2016
mips
title
android-securityexception
java.util.logging
alamofire
nancy
radgridview
eip
esoteric-languages
mvc-mini-profiler
aws-sdk
boost-icl
lilypond
visual-glitch
pagespeed
displaytag
highstock
comparator
gmock
appirater
spotipy
openmdao
alm
cognos-bi
code-snippets
sammy.js
github3.py
gnat-gps
tex
xdocreport
loading
branching-and-merging
glm-math
http-request
photos
memory-mapping
sonarlint-eclipse
user-defined-fields
magic-draw
pair-programming
py2neo
materialized-path-pattern
chromium-os
pure-css
latin
dotnetnuke-7
wso2developerstudio
ng-grid
cifilter
xdoclet
query-by-example
fink
httpruntime.cache
user-management
crouton-os
jbase
concurrentmodification
xenomai
django-urls
rubaxa-sortable
sapscript
apache-commons-daemon
omnifaces
zend-currency
zxspectrum
broadband
bcache
infosphere-spl
mruby
encryption-asymmetric
ss7
parallel-testing
file-not-found
multiautocompletetextview
ice-cube
script#
nevron
kaleidoscope
chart-director
wimax
joomla3.1
veracity
httponly
koken
node-redis
landscape-portrait
listactivity
jqote
tmx
mtu
photolibrary
commerceserver2007
application-planning
wspbuilder

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App