签出这个答案:
在不同目录中的不同 ant 脚本中运行特定目标
我建议您的子模块构建应该引发错误,而不是尝试复制日志解析逻辑。
更新
如果这是为了支持部署而设计的,也许您应该考虑一个 groovy 脚本?会更好地支持异常条件:
def ant = new AntBuilder()
scanner = ant.fileScanner {
    fileset(dir:".", includes:"test*/build.xml")
}
scanner.each { f ->
    try {
        ant.ant(antfile:f)
    }
    catch (e) {
        ant.mkdir(dir:"backup")
        ant.move(todir:"backup", file:f.parent) 
    }
}
Groovy 具有出色的 ANT 集成,也可以嵌入到您的 ANT 构建中:
<target name="run">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
    <fileset id="buildFiles" dir="." includes="test*/build.xml"/>
    <groovy>
        project.references.buildFiles.each { 
            def f = new File(it.toString())
            try {
                ant.ant(antfile:f)
            }
            catch(e) {
                ant.mkdir(dir:"backup")
                ant.move(todir:"backup", file:f.parent) 
            }
        }
    </groovy>
</target>