Here i need to validate the paramters like if user give the input parameter as "-test" or "-blah" or anyother parameter, then i should throw the error as "unregonized parameter". i tried by iterating through the paramters as %1 %2 etc. IF "%1"=="" ( GOTO : ERROR3 ) IF "%1"=="-input1" ( SET value1=%2 ) @IF "%3"=="-input1" ( SET value1=%4 ) @IF "%5"=="-input1" ( SET value1=%6 ) @IF "%7"=="-input1" ( SET value1=%8 ) IF "%1"=="-input2" ( SET value1=%2 ) @IF "%3"=="-input2" ( SET value2=%4 ) @IF "%5"=="-input2" ( SET value2=%6 ) @IF "%7"=="-input2" ( SET value2=%8 ) IF "%1"=="-input3" ( SET value3=%2 ) @IF "%3"=="-input3" ( SET value3=%4 ) @IF "%5"=="-input3" ( SET value3=%6 ) @IF "%7"=="-input3" ( SET value3=%8 ) // some codes here : ERROR1 ECHO "ERROR1" GOTO : END : ERROR2 ECHO "ERROR1" GOTO : END : ERROR3 ECHO Usage -input1 "value1" -input2 "value2" -input3 "value3" : END shift /?Changes the position of replaceable parameters in a batch file.Math Works does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.

Validating parameters in batch files video

:: In order to get the parameter count from WSH we will call this script :: three times in three different ways.

The first time, it'll run the code in this :: section just as any normal BATCH script would.

and leave %0 and %1 [email protected] off setlocal set "value1=" set "value2=" set "value3=" : Parse set "Param=%~1" if not defined Param goto Validate if "%Param%"=="-input1" set "value1=%2" & goto Next if "%Param%"=="-input2" set "value2=%2" & goto Next if "%Param%"=="-input3" set "value3=%2" & goto Next goto Error1 : Next shift & shift goto Parse : Validate if defined value1 if defined value2 if defined value3 goto Main goto Error2 : Main echo %value1% %value2% %value3% goto End : Error1 echo Invalid Parameter: %1 %2 goto End : Error2 echo Usage %~nx0 -input1 "value1" -input2 "value2" -input3 "value3" goto End : End endlocal @echo off setlocal Enable Delayed Expansion rem Define the list of parameters set params=-input1 -input2 -input3 rem Initialize the array of parameters and their values set n=0 for %%a in (%params%) do ( set /A n =1 set param[%%a]=!

More generally, the arguments consist of a number of options prefixed with "-", then optionally (for backwards compatibility) the source filename and/or stylesheet filename, then a number of parameters provided as keyword=value pairs.

For backwards compatibility with previous releases, the prefixes "-s:" and "-xsl:" can be omitted provided that the source document and the stylesheet are the last two options before any keyword=value parameters.

The options must come first, then the file names if present, then the parameters.

Keep in mind, though, that these "features" may vary with the operating systems used.

The batch file's limitation to handle parameters up to I know of several occasions where these seemingly useless "features" proved very handy.

Also keep in mind that labels cannot contain delimiters (space, comma, semi-colon, etcetera), they must be unique, and that only the first 8 characters are used (so the first 8 characters must be unique! This technique is best used when each valid value for %1 has its own batch code to process it: NUL IF ERRORLEVEL 1 ( ECHO Invalid argument: %1 ECHO.