我有几个bat文件运行更多的文件来构建这个项目。这是个忙乱的过程。我把蚂蚁的档案做好了.
有一个BAT文件,当它成功运行时,可以在控制台上打印成功的生成。成功构建是控制台输出的最后一行。
到目前为止,我已经在我的ant脚本中写了这个。
<project name="MyProject" basedir=".">
<property name="buildC" value="${basedir}/build-C" />
<exec dir="${buildC}" executable="cmd" os="Windows XP">
<arg line="/c test.bat > test.log"/>
</exec>
<loadfile property="buildC.log" srcFile="${buildC}/test.log">
</loadfile>
</project>测试( test.log文件的最后一行)是否成功构建。如果是然后执行下一个任务,否则失败。
我试着用失败的任务来帮助你。有人能指点我吗?
发布于 2011-07-07 21:08:32
可以使用buildC.log任务的嵌套条件检查fail属性:
<fail message="test.bat failed">
<condition>
<not>
<matches pattern="${line.separator}BUILD SUCCESSFUL$" string="${buildC.log}" />
</not>
</condition>
</fail>您可能需要稍微调整一下模式才能使其工作,具体取决于test.bat脚本所编写的内容。默认情况下,matches将应用于整个字符串,因此只有当成功消息构成文件的最后一行时,上面的内容才会匹配。
您还可以考虑使用test.bat任务outputproperty属性捕获来自outputproperty的输出。
<exec dir="." executable="sh" outputproperty="buildC.log">
<arg line="/c test.bat" />
</exec>(注意,arg行中删除了shell重定向。)
发布于 2011-07-07 21:29:59
如果要使用最后一行,请使用带尾过滤器lines="1“的过滤器链,请参见蚂蚁手册FilterChains
之后,使用诸如弗拉卡或[医]鹿角等if/else构造的Addon来检查属性=
<project xmlns:fl="antlib:it.haefelinger.flaka">
<loadfile srcfile="your.log" property="buildsuccess">
<filterchain>
<tailfilter lines="1" />
<!-- also possible if needed -->
<trim/>
<striplinebreaks/>
<!-- also possible if needed // -->
</filterchain>
</loadfile>
<fl:choose>
<fl:when test="'${buildsuccess}' eq 'BUILD SUCCESSFUL'">
<echo>execute new task..</echo>
</fl:when>
<fl:otherwise>
<fail message="Houston we have a problem.."/>
</fl:otherwise>
</fl:choose>
</project>或使用条件=的标准蚂蚁方式
<project default="main">
<target name="checklog">
<loadfile srcfile="props.txt" property="buildsuccess">
<filterchain>
<tailfilter lines="1" />
<!-- // also possible if needed -->
<trim/>
<striplinebreaks/>
<!-- also possible if needed // -->
</filterchain>
</loadfile>
<condition property="buildOK">
<equals arg1="${buildsuccess}" arg2="BUILD SUCCESSFUL"/>
</condition>
</target>
<target name="whatever">
<fail message="Houston we have a problem.." unless="buildOK"/>
<!-- if not failed then you'll go on with your other tasks here .. -->
</target>
<target name="main" depends="checklog,whatever"/>
</project>https://stackoverflow.com/questions/6617007
复制相似问题