我试图让一个exec的子进程的STDOUT/STDERR通过Perl中的管道返回到父进程.我所看到的最接近我想做的是:http: //forums.devshed.com/perl-programming-6/exec-and-redirecting-stdout-stderr-168501.html
以下是我想要做的事情的简要示例.我也试过上面链接的一个变种.我看不出我做错了什么......
#!/usr/bin/env perl
use strict ;
use warnings ;
my $cmd = "/usr/bin/who -a" ; # anything to stdout
pipe( READER, WRITER ) ;
my $child = fork() ;
if ( $child ) {
print "I am the parent: My pid = $$ junior = $child\n" ;
close( WRITER ) ;
my @output = <READER> ;
print @output ;
print "parent is DONE\n" ;
} else {
print "I am the child. My pid = $$\n" …Run Code Online (Sandbox Code Playgroud)