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

hide password text in bat file [duplicate]
how to extractble text from text using batch file
Create exe install with bat file, folders, sub folders
batch: how to pipe dir output to findstr?
How to use “where” command and echo the result to .txt file and set that same .txt file as a variable
I need help on how to stop this batch-file from closing when an illegal character is entered by the user
Trying to copy HTML from one file to another using batch
Echo %PATH% returns Sytem path vaibale + User path variable. ? How do I get only the User Path variable?
How to parse an error in batch file? [duplicate]
ECHO is off error while executing batch file
Requesting Zip then merge zip with an image assistance
xslt count following records
Conditional rename inside for statement
Trying to redirect a batch file for loop to another path
How To Run Exe From USB Automatically
Execute Process Task can't run executable file .bat on Visual Studio 2010 version

Categories

HOME
google-app-engine
checkstyle
c99
github-for-windows
depth
powerpoint
jmx
components
requirements
yandex
big-o
ado.net
spring-session
flume
modal-dialog
accessibility
project-intu
alamofire
google-form
pybossa
screen-readers
glyphicons
video-editing
mapstruct
production
charles
articulate-storyline
springfox
jquery-ias
gulp-watch
systemtime
xunit
definitelytyped
itunes
beautifier
syntax-highlighting
fable-f#
flooding
progress-bar
nsurl
weather
testbed
git-squash
papaparse
hibernate-search
sharding
yowsup
swagger-php
google-earth-engine
connection-pool
health-monitoring
urlsession
apache-stanbol
magento-1.9.3
linqpad
install.packages
glm-math
congestion-control
knime
apache-spark-dataset
monkey-testing
servermanager
clarifai
remedy
reindex
amq
truezip
colorbar
cup
payload
rackspace-cloud
gpg-signature
structuremap4
stripe-connect
envi
neon
i386
scaffolding
vorpal.js
shopping
riot
query-by-example
bizagi
project-organization
thread-sleep
asyncdisplaykit
vhosts
concurrentmodification
file-move
jdi
include-guards
text-search
cgi-bin
visual-sourcesafe-2005
dulwich
rdflib
skspritenode
bufferedinputstream
android-broadcast
dbaccess
create.js
malformedurlexception
amslidemenu
scriptaculous
http-patch
cnf
flex++
kaleidoscope
scmmanager
actiondispatch
jquery-address
pinch
ikimagebrowserview
saxparseexception
luajava
objective-j
isapi-extension
openfaces
zen
dojo-dnd
xpsdocument
todos
application-planning
blind

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App