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

Registry Search & Replace Batch file
Write detected result to text file
Cannot start .exe file propetly because config
SAS batch jobs: executing multiple scripts through the same local server connection
If statement inside For loop in batch script
Unmap and map network drive using batch script
Exlcude certain file extensions from random file selection - batch script
Generate text files
Commad prompt remains open after calling a program from batchfile
Return users mapped drive letter from network drive remote
Batchfile: If file exist move it to subdirectory
Having troubles with batch files
ffmpeg batch script image+audio fix
Running two batch files in one build step of TeamCity 9
.bat Error: 'http:' is not recognized as an internal or external command, operable program or batch file
Batch if first time starting

Categories

HOME
facebook-oauth
jax-rs
jmx
web-hosting
title
octave
fhir
plink
capistrano3
azure-iot-hub
searchview
android-7.0-nougat
google-data-studio
pyramid
jquery-ias
dpdk
pimcore
comparator
windows-server-2003
gp
failover
livelink
mockjax
clickjacking
hreflang
github3.py
fiware-cygnus
docfx
playframework-2.1
graphhopper
opensmpp
comparison-operators
ogc
wmp
softmax
naming
dbnull
sharp-snmp
bindingnavigator
memory-mapping
dapper-simplecrud
monkey-testing
httr
openresty
insight
mongotemplate
backbone-collections
slackware
omxplayer
redistributable
actor-platform
burrows-wheeler-transform
delta
cifilter
vorpal.js
swizzling
grass
exim4
highland.js
relativelayout
pypiserver
zscript
typemock
amiga
haskell-warp
fail2ban
rrule
dot.js
mass-assignment
wcm
template-deduction
codeplex
matrix-inverse
gd-graph
mysql-error-1044
jeromq
cffile
insert-id
nokia-s40
zope.interface
os.system
extconf.rb
isa-swizzling
listactivity
mbeans
zend-rest
qtabbar
wcf-proxy
pbcopy

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