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

finding encoding type using batch script
Putty SFTP client - “error while reading: failure”
Batch File Playlist random sort
use DIR command output in batch
How to overwrite file which is using by an application, with ftp commands
Delete Last line from txt file by using Batch
Batch file - restart program after every 20 minutes
Move files from folder to new folder based on # of files
Access Denied…?
Running a .bat only within sub-directory from a .bat in root directory?
how to print month name in file name by using bat
Batch Rename contents of ZIP file to ZIP file name
Random option batch file
Parameter Passing through a Batch File
running multiple jobs from a batch file in pentaho
Removing duplicate lines with sed in batch

Categories

HOME
kentico
wakanda
ecmascript-6
3d
graphics
replace
access
edge
newrelic
parameters
iis-6
gluon-mobile
flume
32bit-64bit
pcl-crypto
appcelerator-studio
plist
emoji
cmdb
google-form
frequency-distribution
plink
cumulocity
shortest-path
sse
pagespeed
ios10.2
tosca
has-and-belongs-to-many
intersystems-cache
winexe
winpe
python-2.6
code-snippets
android-gridview
gojs
gnat-gps
dynamic-jasper
arduino-ide
getlasterror
diacritics
oracle-service-bus
outputcache
tcc
puredata
lampp
linter
yii2-api
reportservice2010
insight
zenhub
amq
monkey
rackspace-cloud
cmp
rocks
cudd
pacemaker
appscale
data-protection
aurora
exim4
design-principles
spring-retry
xenomai
oracle-spatial
zen-cart
page.js
zscript
apache-commons-daemon
post-commit-hook
contrast
teaspoon
machine-instruction
rmysql
reflector
cancellation
tinyxml
decoupling
dsym
websphere-esb
gtm-oauth2
modular
server-administration
android-sdk-2.3
argouml
wimax
zope.interface
rmiregistry
subproject
commerceserver2007
ie-compatibility-mode
delimited-text
isapi-extension
nstokenfield
mathematical-notation
asynchronous-wcf-call
software-lifecycle
todos
localizable.strings
image-capture

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