2012-06-29 120 views
2

我有一个名为Formalbuild.bat的批处理文件,它将采用名为componentName的参数名称。如何将参数数组传递给批处理文件?

例如,我将构建如下的不同组件。

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

是否可以创建组件名称的数组并将逐个组件传递给批量文件以进行构建?

回答

4

由于只有组件名称的变化,您可以使用for循环,甚至更好for/f循环。

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

如果组件列表很长,你也可以将它们分为多行

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

不是一个简单的计数循环就足够了吗?

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

用适当的数字替换N

如果你想在命令行中运行它,然后使用

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

而且,因为在你的问题中的PowerShell标签(虽然你从来没有提到它):

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

更换N的实际值,像往常一样。

+0

我已经更新了我的问题,因为它是给假设我可以遍历通过改变最后一位数字。 – Samselvaprabu

1
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 
相关问题