下面是我的问题的一个简单的例子。 这里exec应该给出一个错误,因为xecho不存在。
题
有没有办法让Capture::Tiny捕获Parallel::ForkManager的输出?
#!/usr/bin/perl use strict; use warnings; use Parallel::ForkManager; use Capture::Tiny 'capture'; my ($stdout,$stderr,$exit) = capture { my $pm = Parallel::ForkManager->new(5); my $pid = $pm->start; if (!$pid) { no warnings; # no warnings "exec" is not working exec("xecho test"); $pm->finish; } }; print "$stdoutn"; print "$exitn"; print "$stderrn";
无法从本地机器发送电子邮件到谷歌
不能在Linux上编译C ++代码,但可以在Mac OS上编译
添加init.d服务(shell中的chkconfig / autocomplete)
计算Windows上的文件夹的校验和,并在Linux上validation
stream浪的同步文件夹不能实时在virtualBox上运行
带有Bash参数的Perl标准input
Gnuplot 4.6 xtics标签消失
Bash脚本来查找文件中每个字母的频率
用__attribute__((section(“STACK”))把一个variables准确地放在“STACK”部分有什么意义?
您不能使用Capture::Tiny捕获子进程的输出,但可以使用Parallel::ForkManager的run_on_finish方法:
use strict; use warnings; use Capture::Tiny qw(capture); use Data::Dump; use Parallel::ForkManager; my $pm = Parallel::ForkManager->new(5); $pm -> run_on_finish ( sub { my ( $pid,$exit_code,$ident,$exit_signal,$core_dump,$data_structure_reference ) = @_; my $info = ${$data_structure_reference}; print "Received from child: n"; dd $info; } ); my $pid = $pm->start; if (!$pid) { my ($stdout,$exit) = capture { sleep 4; exec("xecho"); }; my $info = {stdout => $stdout,stderr => $stderr,exit=> $exit}; $pm->finish(0,$info); } print "Master: waiting for child..n"; $pm->wait_all_children;
输出:
Master: waiting for child.. Received from child: { exit => 0,stderr => "Can't exec "xecho": No such file or directory at ./p.pl line 28.n",stdout => "",}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。