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

Copying a file that doesn't have a file extension in batch
Running elevated cmd.exe in batch script with elevate.exe
How to generate key strokes from a batch file?
Open command window via batch file when cmd.exe is blocked
Bat file for hide/unhide
Batch Error In Number Guesser
Moving folder to different location but only looking at first five characters
How to create a GUI using batch or other programming languages
Append output to file: “File not found”
Recursively search sub-folders and delete all files in sub-folders older than 6-months
Bat to run Android_Server from cmd & extra window for port forwarding
Get full and correct path from registry value via batch file
DOS - why can't I run two for loops one after another?
Get and use current folder name inside a batch file
Batch Script to copy base64 encoded image to new text file
cmd batch job create directory not working

Categories

HOME
algorithm
cygwin
embedded
c++11
string
forms
gpu
jmx
saml-2.0
telegram-bot
banner
frontend
crystal-lang
pkcs#11
modal-dialog
categorical-data
minecraft-forge
appcelerator-studio
stellar.js
zerobrane
screen-readers
gruntfile
connector
gmm
user-experience
pagespeed
ember-cli
inno-download-plugin
object-storage
roundup
dapper-extensions
tiki-wiki
definitelytyped
google-cloud-print
amazon-quicksight
tpm
tizen-tv
realm-mobile-platform
boost-asio
left-join
database-comparison
simplecv
mailkit
hard-drive
indy10
mnist
sql-server-ce
imagenet
graphhopper
reactivekit
flatmap
stringtokenizer
softmax
print-css
avcapturedevice
twilio-click-to-call
stdmap
bbpress
angular2-testing
model-associations
swizzling
yajsw
blitline
directdraw
vhosts
assertion
dynatree
haskell-warp
alloy-ui
xmltype
mmwormhole
procedural-programming
pseudo-class
easyrtc
wcm
nsmenu
gii
square-bracket
drupal-nodes
gtm-oauth2
ebay-lms
kogrid
nebula
android-loadermanager
nokia-s40
tournament
drawtobitmap
mbeans
svk
presentation-layer
resharper-6.0
non-clustered-index
office-2007
message-passing
nstokenfield
request-headers
echo3
purepdf
google-wave
sqlobject
httpcookie

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile