使用Ant,检查是否有特定的字符串在文件中找到 [英] Using ant, check if a particular string is found in a file

查看:118
本文介绍了使用Ant,检查是否有特定的字符串在文件中找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是,使用WAITFOR条件,蚂蚁应该定期检查,如果字符串成功打造会显示在日志文件中。如果找到该字符串,那么应该执行特定动作。

My requirement is that, using waitfor condition, ant should periodically check if string "Build Successful" is displayed in log file. If the string is found, then particular action should be performed.

推荐答案

下面是你可以这样做的一种方式的例子:

Here's an example of one way you might do this:

<target name="wait-for">
    <waitfor maxwait="15" maxwaitunit="second" timeoutproperty="build.timeout">
        <resourcecontains resource="build.log" substring="Build Successful" />
    </waitfor>
    <antcall target="build-success" />
</target>

<target name="build-success" depends="build-fail" unless="build.timeout">
    <echo message="Success" />
</target>
<target name="build-fail" if="build.timeout">
    <echo message="Fail" />
</target>

使用 resourcecontains 条件查找在指定资源串 - 在这种情况下,文件build.log'。
如果它没有在规定时间内找到, build.timeout 属性设置。有两个目标,一个是要运行
如果字符串被发现,对方如果不。如果目标属性
C>,除非取决于被用来做的if-else逻辑的需要。如果你只需要采取行动在成功的情况下的的失败,你可以稍微简化。

Use the resourcecontains condition to look for the string in the named resource - in this case the file 'build.log'. If it's not found in the allotted time, the build.timeout property is set. There are two targets, one that is to be run if the string is found, the other if not. The 'target' attributes if, unless, and depends are used to make the if-else logic need. If you only need to take an action in the case of success or failure, you can simplify slightly.

这篇关于使用Ant,检查是否有特定的字符串在文件中找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆