How to split a string and use it inside a for loop in ant script?

吃可爱长大的小学妹 提交于 2019-12-22 06:49:23

问题


I am having a list of machine ips in a ant property.

<property name="machines" ip="10.10.10.1;10.10.10.2;10.10.10.3"/>

I have to copy one file to all the machines(all the machines are windows machines). So I want to split this string and to use it inside a for loop. Inside that forloop i will execute the copy command.

<exec executable="cmd.exe">
<pre>
</pre>
<arg line="/C COPY /Y sample.txt \\${machine_ip}\Shared_folder\sample.txt"/>
<pre>
</pre>
</exec>

Now how to split and use it inside for loop?


回答1:


Easiest way is to use the ant-contrib features

<for list="10.10.10.1;10.10.10.2" delimiter=";" param = "val">
<sequential>
<echo message = "val = @{val}"/>
</sequential>
</for>



回答2:


If you can't use ant-contrib, an alternative would be to write your own custom Ant task to split the string and execute your command for each token.

Alternatively, since you are executing a Windows-specific command anyway, you could do the split/loop logic in a batch script and exec that, passing the whole properties string.



来源:https://stackoverflow.com/questions/6214069/how-to-split-a-string-and-use-it-inside-a-for-loop-in-ant-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!