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

Detecting if a file is open in a batch file
How to return to the original directory after invoking change directory in DOS batch?
Non-blocking batch file execution
Bat file includes
In batch files calls to executables are sequential or not?
Log in to windows by .bat file
Get free space of “C:” drive using batch file [duplicate]
Running a batch script by right clicking any file
Save and Load .bat game — Error with single numbers
Running several batch-files in a batch-file
How can I use batch to determine if a computer is using FAT32 or NTFS?
Cygwin terminal batch file - cannot find file, but can if I run the cmd myself it does
Batch file PATH overflow
Problem with my batch script
String substitution (asterisks) in Batch files?
How to get first file in subfolder while recursing through subfolders using windows batch

Categories

HOME
eclipse
azure-stream-analytics
youtube-data-api-v3
static
apache-spark-mllib
spring-data-redis
gradient
can
replace
edge
parameters
pyqt4
regular-language
jetty
nuget-package
webix
odoo-8
fosrestbundle
octave
rtf
atlassian-stash
firefox-addon
fileserver
replication
microsoft-ocr
user-experience
guzzle
springfox
cgbitmapcontext
draft-js-plugins
jquery-multiselect
progress-bar
linked-data
handler
exchangewebservices
subclass
realm-mobile-platform
calculation
aws-codecommit
anki
spring-security4
code-snippets
nested-lists
browser-extension
xajax
docfx
reactivekit
timing
node-mssql
jvmti
apache-stanbol
congestion-control
outputcache
placeholder
knime
mesosphere
mschart
lightning
corruption
payara-micro
ngmaterial
er-diagram
check-mk
baidu
ampps
pure-css
grails-plugin
flex-monkey
reporting-services-2012
resourcemanager
gogs
vorpal.js
redis-cluster
ikiwiki
fink
blitline
toast
custom-errors
oracle-spatial
rate-limiting
intel-c++
ons-api
opserver
toolkit
jdk1.7
cwrsync
variadic-templates
theos
execve
deform
teaspoon
appserver
entry-point
codeplex
parallel-testing
lnk
android-audiorecord
bin
visual-studio-express
hibernate-entitymanager
scrypt
oocss
workitem
stacky
patricia-trie
nokia-s40
garbage
objectquery
appjs
failing-tests
ikimagebrowserview
htdocs
mbeans
event-receiver
metaweblog
sifr
complex-event-processing
sqlobject
movieplayer

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