使用ant 的exec时不能随意省略可执行文件的扩展名

我原来这样写:

<exec dir="${another.project}" executable="ant">
  </exec>

结果:Execute failed: java.io.IOException: CreateProcess: ant error=2 

后来把 executable="ant" 改成 executable="ant.bat" 就成功了

官方文档这样说:

Windows Users

The <exec> task delegates to Runtime.exec which in turn apparently calls ::CreateProcess. It is the latter Win32 function that defines the exact semantics of the call. In particular, if you do not put a file extension on the executable, only ".EXE" files are looked for, not ".COM", ".CMD" or other file types listed in the environment variable PATHEXT. That is only used by the shell.

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

<target name="help">
  <exec executable="cmd">
    <arg value="/c"/>
    <arg value="ant.bat"/>
    <arg value="-p"/>
  </exec>
</target>

猜你喜欢

转载自zhangjijun.iteye.com/blog/2157716
今日推荐