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

Get Filename from Filepath
how to suppress messagebox popups while running batch file
Setting variables with variables - Batch
Is there any Windows command to uninstall an application?
What DOS script command “gets” a value from the console?
Batch File to rename txt file
Copying files based on date modified
Batch script to prefix file names
Resize command prompt through commands
(Windows batch) Goto within if block behaves very strangely
How do I handle errors in a batch file that calls sqlplus, because sqlplus doesn't set ERRRORLEVEL on error or failure?
Guest program exited with non-zero exit code: 1
'If' condition in batch file
Batch File - Tasklist - FindStr
batch file to name folder based on filename
xcopy does not create directory structure

Categories

HOME
phpword
deep-learning
awk
angular2-material
socket.io
grafana
google-cloud-functions
switch-statement
tail
hugo
babeljs
data-visualization
banner
angularfire2
extjs4.2
mautic
redis-sentinel
naivebayes
openbugs
frequency-distribution
plink
libusb
package.json
pyramid
topology
apache2.4
visual-glitch
backpack-for-laravel
dataflow-diagram
inno-download-plugin
perlbrew
angularjs-components
android-maps
subclass
user-defined-functions
raft
sessionstorage
c9.io
azure-arm
android-softkeyboard
android-ibeacon
wc
getchar
textsum
openal
configurationmanager
x-ray
google-cse
pair-programming
colorbar
dt
rackspace-cloud
juice-ui
usart
custom-lists
hadoop-2.7.2
watch-os-2
i386
php-socket
bizagi
yajsw
np-spring
maybe
opl
branch-and-bound
rdflib
alloy-ui
bufferedinputstream
fail2ban
diff3
shopizer
iiop
addressing-mode
administration
xml-namespaces
tinyxml
buffering
multitasking
spring-3
hibernate-entitymanager
cffile
merb
css-reset
jquery-1.9
faye
lambdaj
jsr286
jquery-address
box2d-iphone
user-tracking
android-holo-everywhere
twitterizer
timertask
binomial-heap
zend-rest
tui
google-wave

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