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

How to Specify Drive Letter on Remote Server for Copy or XCopy Command
Batch to blat (SMTP) e-mail multple files
Cmd - Unbalanced parenthesis
How to make a batch script to create a folder from only numbers in file names
How to check if steam is running in batch, then execute a display switch if steam is not running
Query registry based on value inside key without knowing key name
Simple if in .bat or .cmd to check if booted in safe mode or not
How to delete the first line in multiple text files without appending CRLF to the end of the file
Replace specific text in csv via commandline
ErrorAction SilentlyContinue Missing expression after unary operator
How can I list file which's name contains exclamation marks in dos batch with the delay expansion enabled?
Reading a txt line by line in a batch file [closed]
What is wrong with my .bat file?
Batch malfunction
how to run a command for each subfolder
How to return exit status from an HTA (vbscript) to the calling Batch file

Categories

HOME
facebook-oauth
redux-form
datastore
static
spring-data-redis
shiro
error-handling
ms-access-2016
spring-data-mongodb
emscripten
google-admin-sdk
frontend
project
appcelerator-studio
emoji
ycsb
php-5.6
automatic-ref-counting
enterprise-architect
flash-player
capistrano3
boost-icl
breadth-first-search
gmock
dapper-extensions
stackexchange
corpus
has-and-belongs-to-many
ms-access-2003
angular-translate
tpm
winpe
turfjs
installshield-le
nested-lists
python-import
chef-solo
bindingnavigator
berkeley-db-je
apache-directory
gitlist
mschart
vugen
reindex
libjpeg
mouseleave
trigger.io
branch-prediction
google-cloud-console
vulcanize
dotnetnuke-7
dimension
cfchart
database-relations
jnlua
video-player
bcache
grouping-sets
variadic-templates
parallel-testing
renderer
fpdi
dsym
websphere-esb
git-repo
breakout
insert-id
robotlegs
web-farm
floating-point-exceptions
hibernateexception
procedures
saxparseexception
matlab-load
google-ajax-api
cuteeditor
load-time
delimited-text
rowlex
interprocess
django-piston
lalr
wysiwym
dsoframer

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