问题
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} & 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