`

Ant 使用Ant脚本执行bat文件

    博客分类:
  • Ant
Ant 
阅读更多

 

有如下文件结构:

 

root

    ---- batDir

             ---- my.bat

    ant-build.xml

    

    ant-build.xml文件的内容

 

<project name="example" default="test">
	<target name="test">
		<exec executable="cmd.exe" output="log.txt" dir="./batDir">
			<arg value="/c"/>
			<arg value="my.bat"/>
                        或
                        <arg line="/c my.bat"/>
		</exec>
	</target>
</project>

 

这样,就可以执行my.bat文件了。

dir属性指定了执行cmd.exe命令的目录。output指定了输出的日志文件。

arg标签的value和line都是给cmd.exe传递参数的。区别是line会将值按照空格分开,作为多个参数传递给命令行。value是将值作为一个整体,传递给命令行,多个value传递多个参数。官方推荐使用value。

 

<exec>标签的属性:

必须的:

command (if executable is not  specified) 不推荐

executable (if command is not  specified)

 

可选的:

append

dir

failifexecutionfails

failonerror

newenvironment

os

output

outputproperty

resultproperty

timeout

vmlauncher

 

<arg>标签的属性:

key

file 

path 

value 

 

参考资料:<<Ant Developer’s Handbook>>及网络

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics