在Perl中执行命令时出现问题

问题描述

我有以下代码

chdir glob "/home/test/test1/test2/perl*";
@testList = exec "cat test.in | grep build | awk '{print \$2}'";
foreach my $testList(@testList) {
    chdir "/home/test/test1/$testList";
    exec "cat test.out | grep -w 'PASSED'";
}

运行上面的代码后,它仅提供以下内容输出

chdir glob "/home/test/test1/test2/perl*";
@testList = exec "cat test.in | grep build | awk '{print \$2}'";

,但下面的其他两行除外。我只想要这些行的输出

foreach my $testList(@testList) {
    chdir "$opts->{/home/test/test1$testList";
    exec "cat test.out | grep -w 'PASSED'";

不是

chdir glob "/home/test/test1/test2/perl*";
@testList = exec "cat test.in | grep build | awk '{print \$2}'";

请帮助。

解决方法

execsystem返回退出代码。

尝试:

@testList = `cat test.in | grep build | awk '{print \$2}'`;