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

Return cscript output to batch [duplicate]
Ignore CRC errors
Assign the directory of a file to a variable
Setting variable value to for loop
2 individual command lines with same realtime variable
CMD/Batch - Deleting a file with UTF-8 Characters in the filename (ex. Japanese, Chinese characters)
xcopy doesn't work with relative path and environment variable
Noob assignment about batch script, thx in advance [closed]
Q: How do I parse relevant IP addresses from netstat and redirect it to NSlookup in a batch script?
batch file: Save exported text file as encoding utf-8
If Processor=xx-bit do this in batch?
Changing file extentions in batch
Removing second extension from file name [duplicate]
Reading Multiple Lines from a Text File using batch
Batch file to move files based on a list Without overwriting Old file and number of copies
Batch if statements don't seem to work

Categories

HOME
windows
string
apache-jena
amp-html
ns-3
mjml
pyqt
case
sh
rendering
opendj
seo
jax-ws
project
startup
project-intu
opengl-es-3.0
spring-social
symmetricds
atlassian
dynamic-sql
asp.net-mvc-viewmodel
mapstruct
shortest-path
boost-icl
windows-xp
google-maps-autocomplete
asciidoctor-pdf
springfox
ember-cli
pchart
xcode-ui-testing
data.stackexchange.com
spotipy
failover
sammy.js
alphabetical
openproject
playframework-2.1
skylink
linqpad
glm-math
show-hide
flask-login
textsum
mongotemplate
css-transforms
monkey
objectscript
vibrate
ampps
pocketsphinx-android
polyline
usart
simplepie
centrifuge
installshield-2010
google-query-language
mediametadataretriever
state-restoration
pypiserver
forwarding
zen-cart
dronekit-android
liquid-layout
apache-commons-daemon
cwrsync
adehabitathr
delayed-execution
execve
contrast
formview
device-tree
genymotion-call
ss7
kissfft
android-framework
multiautocompletetextview
git-repo
mt4j
hibernate-entitymanager
process-explorer
css-reset
pstack
objectquery
jdb
jsr286
mbeans
uipagecontrol
http-daemon
silent
filesystemobject
int64
soappy
appliance

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