perl正则表达式多行模式无法匹配问题

麦当猫 发布于 2014/06/03 16:46
阅读 842
收藏 0

用perl脚本调用ant进行批量编译,希望编译之后列出编译失败的模块数量和列表,代码如下:


open MODLIST, "< list.txt" or die "can't open list.txt:\n $!";
$faild = 0;

while(<MODLIST>) {
	chomp;
	$antmsg = `ant -Dmodel=$_ 2>&1`;
	print "\n====ant message====\n$antmsg\n====ant message====\n";
	if($antmsg =~ "/^BUILD FAILED$/m"){
		print "$_ build faild! check the antlog";
		push @faillist, $_;
		$faild++;
	}
}

close MODLIST;

print "$faild models failed";
for(@faillist){
	print;
	print "\n";
}

      开始想用system函数调用ant通过返回值确定是否成功,经过测试发现不论ant执行成功或是失败,system返回值始终为0.于是改用捕获ant输出的方式,但结果是“/^BUILD FAILED$/m”部分始终匹配不成功。在正则表达式工具中测试过模式和文本可以匹配。

    以下是list.txt中有两条记录时的执行结果:

D:\workspace\source\xxxx\test\uat-test>perl test.pl

====ant message====
Buildfile: D:\workspace\source\xxxx\test\uat-test\build.xml

BUILD FAILED
D:\workspace\source\xxxx\test\uat-test\build.xml:80: The element type "path" mu
st be terminated by the matching end-tag "</path>".

Total time: 0 seconds

====ant message====

====ant message====
Buildfile: D:\workspace\source\xxxx\test\uat-test\build.xml

BUILD FAILED
D:\workspace\source\xxxx\test\uat-test\build.xml:80: The element type "path" mu
st be terminated by the matching end-tag "</path>".

Total time: 0 seconds

====ant message====
0 models failed


    请各位网友指点:

    1.为何system函数调用ant,不论执行结果成败始终返回0?

    2.为何/^BUILD FAILED$/m部分无法匹配

    多谢!

加载中
0
麦当猫
麦当猫
问题已解决,我的代码有bug:匹配模式上不应该加引号。
返回顶部
顶部