Running a .cmd file from Ant

瘦欲@ 提交于 2019-12-19 07:30:08

问题


Is it possible to run a command (.cmd file) from Ant? Would I need to write Java code for this?


回答1:


<exec executable="cmd" os="Windows XP">
  <arg value="/C"/>
  <arg value="command to run"/>
</exec>



回答2:


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

Note that .bat files cannot in general by executed directly. One normally needs to execute the command shell executable cmd using the /c switch.

So you would need to do something like:

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

Note that by doing this you have created a dependency of running your ant script in windows.




回答3:


Adding to eradicus answer, you can also execute .bat, .cmd, ... from any directory with argument on your Window machine by

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


来源:https://stackoverflow.com/questions/3713350/running-a-cmd-file-from-ant

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