Link to home
Start Free TrialLog in
Avatar of Software Software
Software SoftwareFlag for Austria

asked on

CMD: Make sure that only one parameter has been passed

Hello,
when a batch-file is executed in cmd. I want to make sure that exactly one parameter has been passed.
How can I do this?
Avatar of Bill Prew
Bill Prew

Just check %2 and make sure it is blank, like:

if "%~2" NEQ "" (
    echo Too many parms entered.
    exit /b
)

Open in new window


»bp
batch script parameters are named %1, %2, %3 ect (up to %9).
So, Just check if %2 hold any value.

But why don't you ignore additional parameters if you arn't interrested in them ?
It is simplier than an akward checking.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.