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

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

问题描述

我的要求是,使用等待条件,蚂蚁应该定期检查日志文件中是否显示字符串构建成功".如果找到该字符串,则应执行特定操作.

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 属性.有两个目标,一个是要运行的如果找到字符串,则另一个如果没有.'target' 属性 if, 除非depends用于使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天全站免登陆