Running .cmd file from Ant

Can I run a command (.cmd file) from Ant? Do I need to write Java code for this?

+6
ant
source share
3 answers
<exec executable="cmd" os="Windows XP"> <arg value="/C"/> <arg value="command to run"/> </exec> 
+10
source share

You can do this using exec . From the ant exec documentation:

Please note that .bat files cannot be directly executed at all. Typically, you want to run the cmd command-line executable with the / c switch.

So you will need to do something like:

 <exec executable="cmd"> <arg value="/c"/> <arg value="batchfile.cmd"/> </exec> 

Please note that in doing so, you created the dependency on running the ant script on Windows.

+8
source share

By adding eradicus to the answer, you can also execute .bat, .cmd, ... from any directory with an argument on your Window machine using

 <target name="test"> <exec executable="cmd" dir="C:/Users/mydir/"> <arg value="/C" /> <arg value="myjob.bat arg1 arg2" /> </exec> </target> 
+1
source share

All Articles