Running a .cmd file from Ant

前端 未结 3 624
臣服心动
臣服心动 2021-01-12 15:35

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

相关标签:
3条回答
  • 2021-01-12 16:11

    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>
    
    0 讨论(0)
  • 2021-01-12 16:19

    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.

    0 讨论(0)
  • 2021-01-12 16:23
    <exec executable="cmd" os="Windows XP">
      <arg value="/C"/>
      <arg value="command to run"/>
    </exec>
    
    0 讨论(0)
提交回复
热议问题