Dilma
Dilma

Reputation: 645

command line argument to a batch file

I want to run a script in commandline like below:

xxxx.bat param1=something1 param2=something2 param3=saomething3

I could do that from the following script:

echo off
cls
@echo first,second arguments :: %1 %2
set %1
set %2
@echo a :::: %a% 
@echo b :::: %b%

I run the script on the command line using the following command,

xxx.bat "a=1" "b=2"

My question is, can I pass the argument without the quotations and can I access the parameters by name in the script directly without using the:

set %1
set %2

Upvotes: 0

Views: 2547

Answers (1)

SomethingDark
SomethingDark

Reputation: 14304

You need to set the variables inside the script if you want the script to be able to use them. You can, however, pass only the values into the script like this:

@echo off
cls
set param1=%1
set param2=%2

Also, as long as the argument doesn't have spaces, you don't need quotation marks.

Upvotes: 1

Related Questions