How to run multiple commands from ant exec task

南楼画角 提交于 2019-12-24 05:44:08

问题


I want to run two dos commands from Ant exec task.

I have tried below code

<exec dir="${testworkspace}\${moduleName}" executable="cmd" failonerror="true" output="${testworkspace}\${moduleName}\BuildConsole_TC${tc_num}.log" resultproperty="execrc">
                    <arg value="/c echo Download Status is ${DownloadStatus}"/>
                    <arg value="/c Load.bat ${moduleName} ${Intapp} ${CcvStatus}"/>
                </exec>

but it executes only first command and skips second. I am trying this on windows OS.


回答1:


This should work. Simply chaining the commands.

<exec dir="${testworkspace}\${moduleName}" executable="cmd" failonerror="true" output="${testworkspace}\${moduleName}\BuildConsole_TC${tc_num}.log" resultproperty="execrc">
    <arg value="/c echo Download Status is ${DownloadStatus} &amp; Load.bat ${moduleName} ${Intapp} ${CcvStatus}"/>
</exec>



回答2:


Why do you need to run two commands in a single <exec> task? Instead, just use a second <exec> task. You can include both in a single target:

 <target name="execute.this">
     <exec dir="${testworkspace}\${moduleName}" 
         executable="cmd" failonerror="true" 
         output="${testworkspace}/${moduleName}/BuildConsole_TC${tc_num}.log" 
         resultproperty="execrc">
         <arg value="/c echo Download Status is ${DownloadStatus}"/>

     <exec dir="${testworkspace}\${moduleName}" 
         executable="cmd" failonerror="true" 
         output="${testworkspace}/${moduleName}/BuildConsole_TC${tc_num}.log" 
         resultproperty="execrc">
         <arg value="/c Load.bat ${moduleName} ${Intapp} ${CcvStatus}"/>
     </exec>

Or better yet, just use the <echo> task:

     <echo message="/c echo Download Status is ${DownloadStatus}"/>
     <exec dir="${testworkspace}\${moduleName}" 
         executable="cmd" 
         failonerror="true" 
         output="${testworkspace}/${moduleName}/BuildConsole_TC${tc_num}.log" 
         resultproperty="execrc">
         <arg value="/c Load.bat ${moduleName} ${Intapp} ${CcvStatus}"/>
     </exec>

If you need the output of the echo task in the same file, you can use the file parameter in the echo command, and the append parameter in the exec task.



来源:https://stackoverflow.com/questions/31401895/how-to-run-multiple-commands-from-ant-exec-task

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