无法在perl中处理Psexec命令上的异常处理

无法在perl中处理Psexec命令上的异常处理,perl,cmd,psexec,Perl,Cmd,Psexec,如果psexec命令失败,或者更重要的是,如果需要更多时间,我试图退出for循环,我在这个程序中使用了time::Out模块,但是psexec命令没有退出,我使用它错了吗?有没有其他办法来处理这种情况 #$nb_secs means number of seconds for my $host1 (@servers){ timeout $nb_secs => sub { # do stuff that might timeout.

如果
psexec
命令失败,或者更重要的是,如果需要更多时间,我试图退出
for
循环,我在这个程序中使用了
time::Out
模块,但是
psexec
命令没有退出,我使用它错了吗?有没有其他办法来处理这种情况

#$nb_secs means number of seconds
  for my $host1 (@servers){
        timeout $nb_secs => sub {
                 # do stuff that might timeout.
                $returnFileNames=`psexec \\\\$host1 cmd /c "dir /s 
                 d:\\dd\` ;
        }; 

        next if $@;
}

SIGALRM
无法传递到进程的原因有很多,您已经发现了其中之一。解决方法是--在后台运行一个单独的进程来监视长时间运行的进程,并在一段时间后终止它。在Windows上,如果使用需要捕获输出的命令,它将如下所示:

# $pid is the id of the process to monitor
my $pid = open my $proc_fh, '-|', "psexec \\\\$host1 cmd /c "dir /s d:\\dd\";

my $pma = "sleep 1,kill(0,$pid)||exit for 1..$nb_secs;"
        . "kill -9,$pid;system 'taskkill /f /pid $pid >nul'";
my $pma_pid = system 1, $^X, "-e", $pma;

# read input from the external process.
my $returnFilenames;
while (<$proc_fh>) {
    $returnFilenames .= $_;
}
close $proc_fh;
#$pid是要监视的进程的id
my$pid=打开my$proc\U fh、“-”和“psexec\\\\$host1 cmd/c”目录/s d:\\dd\”;
my$pma=“睡眠1,杀死(0,$pid)| |退出1..$nb|u秒;"
“杀戮-9,$pid;系统'taskkill/f/pid$pid>nul';
my$pma_pid=系统1,$^X,“-e”,$pma;
#从外部进程读取输入。
我的$returnfilename;
而(){
$returnFilenames.=$\uux;
}
关闭$proc_fh;

穷人的警报是一个由两部分组成的小程序。第一部分最多可计数
$nb_secs
秒,如果监视的进程不再运行,则终止(如果
kill 0,$pid
返回假值)。程序的第二部分,如果到达,将终止被监视的进程。在本例中,我们尝试两种不同的方法(
kill-9…
system'taskkill/f…
)来终止进程。

这是在什么操作系统上运行的?
Time::Out
的文档中说的是
报警(2)不会中断MSWin32上的阻塞I/O,因此“超时”也不会这样做。
@Chris Doyle它正在windows server 2008上运行