Pravin Virkud
Pravin Virkud

Reputation: 107

How to run multiple commands from ant exec task

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.

Upvotes: 4

Views: 7666

Answers (2)

David W.
David W.

Reputation: 107080

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.

Upvotes: 2

Hank Lapidez
Hank Lapidez

Reputation: 2025

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>

Upvotes: 5

Related Questions