Samselvaprabu
Samselvaprabu

Reputation: 18147

How to pass array of argument to batch file?

I am having batch file called Formalbuild.bat ,It will take parameter name called componentName.

For ex. I will build the different components like below.

    Formalbuild.bat ServiceComponent
    Formalbuild.bat DatamodelComponent
    Formalbuild.bat 
                ...
                ...
    Formalbuild.bat SomeXYZComponent

Is it possible to create array of component name and pass one by one component to batch file to do build?

Upvotes: 2

Views: 2916

Answers (3)

jeb
jeb

Reputation: 82267

As only the component name changes, you could use a for loop or even better a for/f loop.

FOR %%C in (ServiceComponent DatamodelComponent SomeXYZComponent ) do (
    call Formalbuild.bat %%C
)

If the list of components is long you could also split them into multiple lines

FOR %%C in (ServiceComponent 
DatamodelComponent
component3
...
component_n
SomeXYZComponent ) do (
    call Formalbuild.bat %%C
)

Upvotes: 4

David Brabant
David Brabant

Reputation: 43499

for %%a in (
    Component1
    Component2
    Component3
    ...
    ...
    ComponentN) do call :FormalBuild %%a

:FormalBuild
set THING_TO_BUILD=%1
REM call your build stuff here with %THING_TO_BUILD% identifying what you are building

Upvotes: 1

Joey
Joey

Reputation: 354466

Wouldn't a simple counting loop suffice?

for /l %%x in (1,1,N) do call Formalbuild.bat Component%%x

Replace N by the proper number there.

If you want to run this on the command line, then use

for /l %x in (1,1,N) do Formalbuild.bat Component%x

And since there is a PowerShell tag in your question (although you never mention it):

1..N | %{Formalbuild.bat Component$_}

Replace N by the actual value, as usual.

Upvotes: 2

Related Questions