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

Batch: Reading in a line from a file that has a colon and exclamation
something wrong with Batch program
Create cmd command with parameters in batch [duplicate]
How to check wso2 identity server has completely started or not using batch file.
batch copy folder located by guid
Batch File 1 time-pad encryption
Batch file to create multiple folders and copy files to all [closed]
Script windows .bat - Get filenames from some folders
pccntmon redirect to text file
Why is string comparison after prompting user for a string/option not working as expected?
Batch file to find a file using regular expression and rename it
Someone can explain me this batch file? [closed]
Access is Denied When Renaming Folder
Batch file value in variable
Use environment variable set by a batch script in the next batch script run
Batch script to rename file with timestamp on FTP server after upload

Categories

HOME
search
phpword
scikit-learn
hyperlink
delphi-7
telegram
case
powerpoint
access
google-cloud-functions
scripting
tail
supervisor
radgridview
pybossa
gource
mvc-mini-profiler
replication
articulate-storyline
spring-async
pimcore
exit
pchart
data.stackexchange.com
flooding
ms-access-2003
datastax-enterprise-graph
weather
cognos-bi
testbed
glib
hibernate-validator
hunspell
jwplayer6
openproject
verifiable-c
metawidget
cin
news
ogc
azure-arm
install.packages
oracle-service-bus
http-request
wc
oim
servermanager
openal
x-ray
azure-cli
context-sensitive-grammar
pdf-conversion
java-websocket
pybrain
reachability
stripe-connect
chromium-os
meteor-packages
microstation
envi
flex4.6
signalr.client
beamer
wso2developerstudio
dup
android-dateutils
observablecollection
refinerycms
freepbx
tracker-enabled-dbcontext
upx
invoke-sqlcmd
jparsec
concept-insights
ascii-art
forwarding
video-player
text-search
public-html
cosine-similarity
big-ip
metatrader5
device-tree
cuba
verold
rcaller
amslidemenu
spring-3
ora-06550
away3d
ice-cube
pclzip
redis-py
multiplexing
denied
xcelsius
webdev.webserver
tournament
diagrams
load-time
silent
rowlex
message-passing
dsl-tools
dojo-dnd
linfu-dynamicproxy
firefox-3
httpcookie
commercial-application

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