How to run multiple commands from ant exec task

2019-07-23 19:15发布

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.

标签: ant dos
2条回答
Rolldiameter
2楼-- · 2019-07-23 19:19

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>
查看更多
ら.Afraid
3楼-- · 2019-07-23 19:33

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.

查看更多
登录 后发表回答