#Parsing arguments to a batch file..

1 messages · Page 1 of 1 (latest)

royal kayak
#
@echo off
if "%~1" == "-a" goto :a

echo no argument !!
goto end

rem **************
rem a
rem **************
:a
echo running a
goto end

rem **************
rem the end
rem **************
:end
hollow thunder
#

Just wanna add something that might be useful:

only arguments %1 to %9 can be referenced by number.``` - SS64

So if you just wanna search **all** given arguments at launch for a certain string then you could just (for example) run ``echo %* | findstr /I "5" | if %errorlevel% == 0 echo Found!``.
In case if it finds the specified string ("5") in the whole variable, it wil say "Found!"
This way you can make it that arguments don't need to be in a specfic order.