【发布时间】:2011-12-09 22:22:28
【问题描述】:
我有一个 perl 脚本,它运行一系列用于回归测试的批处理脚本。我想在批处理脚本上实现超时。我目前有以下代码。
my $pid = open CMD, "$cmd 2>&1 |";
eval {
# setup the alarm
local $SIG{ALRM} = sub { die "alarm\n" };
# alarm on the timeout
alarm $MAX_TIMEOUT;
log_output("setting alarm to $MAX_TIMEOUT\n");
# run our exe
while( <CMD> ) {
$$out_ref .= $_;
}
$timeRemaining = alarm 0;
};
if ($@) {
#catch the alarm, kill the executable
}
问题是,无论我将最大超时设置为多少,警报都不会触发。我尝试过使用 Perl::Unsafe::Signals 但没有帮助。
如果我希望能够捕获它们的输出,这是执行批处理脚本的最佳方式吗?有没有其他方法可以做同样的事情,让我可以使用警报,或者除了警报之外还有其他方法可以让程序超时?
我已经构建了一个测试脚本来确认警报适用于我的 perl 和 windows 版本,但是当我运行这样的命令时它不起作用。
我在 windows 7 x64 上使用 activeperl 5.10.1 运行它。
【问题讨论】: