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

Windows batch file copy based on format, “FILENAME_20131220.txt.pgp”
Batch File Username and Password Save
Batch flatten subdirectorie in multiple files but keep file within
Batch File: Parsing a Registry Key whose name contains the % sign through the FOR command
Using a Batch File to Copy Desktop icons from %userprofile%\Desktop to %public%\Desktop
Calling a WMIC command inside FOR from a batch file hangs the system for indefinite time
Batch, Getting ERROR when randomizing array of numbers, and then adding them
how do I copy files specified in array to another folder
Batch - If not (this) or (that) or (this one) do (that one)? [duplicate]
Using a userinput as a variable in an If statement in BAT
How to take multiple screenshots using VLC Media Player and a batch file
Batch file stop executing after executing the first command
How to fail a executed TFS build when an invoked batch script fails?
How to print .bat script error into summary section when running a TFS build definition
Batch Files - Error Codes
Batch File color mixing (part 2)

Categories

HOME
cheerio
google-spreadsheet
jax-rs
flex
battery
knitr
static-site
cublas
google-apps
dojo
code-coverage
barcode
computer-science
fosrestbundle
commonjs
fhir
jsonpath
selenium-ide
azure-powershell
aws-sdk
chargify
imessage
simpleitk
blade
angular-routing
joptionpane
pimcore
hta
maze
opentk
delimiter
entity-relationship-model
8051
soot
google-earth
angularjs-material
fstream
dsx-desktop
carriage-return
indy10
numpy-broadcasting
servicestack-text
docfx
openproject
jpad
google-data-api
knime
phpdbg
magento-2.0.7
sonarlint-eclipse
hammer.js
rserve
activeperl
datamaps
manova
mongotemplate
payara-micro
context-switch
wpas
edit
headless
excel-dna
css-transforms
lsyncd
cpu-cache
jtree
swingworker
rsa-archer-grc
sandcastle
angular2-testing
redbeard-ios
segment-io
scaffolding
dimension
android-dateutils
qiime
kango-framework
yajsw
ellucian-scribe
dynatree
morton-number
binomial-theorem
rpart
wso2greg
rdflib
dnssec
snoop
procedural-programming
infosphere-spl
boost-program-options
insight.database
matrix-inverse
visual-studio-express
modular
kaleidoscope
poker
actiondispatch
chart-director
web-notifications
rmiregistry
listitem
lambdaj
infobright
hibernateexception
workflow-services
fsevents
resharper-6.0
updatesourcetrigger
nstokenfield
wcf-instancing
xpsdocument
entitykey
information-management
idatareader

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