天道酬勤,学无止境

perl-ipc-run

如何判断 IPC::Run 作业何时完成(How to tell when an IPC::Run job has finished)

问题 是否有一种简单、可靠的方法来判断 IPC::Run 任务何时完成,即任何子进程已退出? 文档令人惊讶地对此保持沉默。 似乎循环pumpable工作,尽管它并没有真正清楚地记录为正确的做事方式: use strict; use warnings; use IPC::Run; use 5.12.0; my $handle = IPC::Run::start(['sleep', '10']); while ($handle->pumpable) { sleep(0.5); # do other stuff in the event loop # so we don't want to block on finish } $handle->finish; print("exited with '" . $handle->result . "'"); 有更好的选择吗? finish块,但是当您等待 proc 完成时,您无法在事件循环中做其他工作。 我很惊讶没有一个简单的 $handle->running 或者 $handle->finished 我错过了一些明显的东西吗? 同样,似乎没有记录的方法来获取孩子(人)的 pid。 回答1 我也找不到干净的方法,只有其他方法。 可以通过与result相关的方法和pumpable (问题中已经使用的内容)获取有关儿童是否正在跑步的信息。

2021-10-08 20:07:32    分类:技术分享    perl   perl-ipc-run

How to tell when an IPC::Run job has finished

Is there a simple, reliable way to tell when an IPC::Run task has completed, i.e. any child process(es) have exited? The docs are astonishingly silent on this. It seems that looping on pumpable works, though it's not really documented clearly as the right way to do things: use strict; use warnings; use IPC::Run; use 5.12.0; my $handle = IPC::Run::start(['sleep', '10']); while ($handle->pumpable) { sleep(0.5); # do other stuff in the event loop # so we don't want to block on finish } $handle->finish; print("exited with '" . $handle->result . "'"); Is there a better option? finish blocks, but

2021-06-27 01:57:47    分类:问答    perl   perl-ipc-run

如何从 IPC::Run3 测试退出状态(How to test the exit status from IPC::Run3)

问题 我正在尝试测试 Perl 模块 IPC::Run3,但很难检查命令是失败还是成功。 我知道如果 IPC::Run3 的参数有问题,它会发出一个退出代码,但是如果参数正常但命令不存在呢? 如何测试以下示例? 有一个子程序来调用 Run3 sub runRun3 { my $cmd = shift; my ($stdout, $stderr); run3($cmd, \undef, \$stdout, \$stderr); # if( $? == -1 ) { if (! $stdout and ! $stderr) { die "Something is wrong"; } else { print "OK \n"; } } 当执行下面的命令$cmds[0] (*nix 系统的ls命令),它按预期打印OK ,但使用命令$cmds[1]它只是说No such file or directory at ./testrun3.pl line 18 。 通过对退出代码的测试,我希望它打印出Something is wrong 。 #!/usr/bin/perl use warnings; use strict; use IPC::Run3; my @cmds = qw(ls silly); runRun3($cmds[0]); runRun3($cmds[1]); 或者在这种情况下

2021-06-26 02:23:46    分类:技术分享    perl   exit-code   perl-ipc-run

How to test the exit status from IPC::Run3

I'm trying to test the Perl module IPC::Run3 but having difficulty in checking whether a command is failed or successful. I know that IPC::Run3 issues an exit code if something is wrong with its arguments, but what about if the arguments are ok but the command does not exist? How can I test the following example? Having a subroutine to call Run3 sub runRun3 { my $cmd = shift; my ($stdout, $stderr); run3($cmd, \undef, \$stdout, \$stderr); # if( $? == -1 ) { if (! $stdout and ! $stderr) { die "Something is wrong"; } else { print "OK \n"; } } when command $cmds[0] below is executed (the ls

2021-05-03 05:00:38    分类:问答    perl   exit-code   perl-ipc-run