in reply to Re: Process ID of qx
in thread Process ID of qx
my $pid = open my $ph, "| $_[0]" or die "$!: $_[0]";
Your open is opening for write instead of read. The command's output goes to STDOUT instead of to your variable. Try this:
sub pidqx { # returns pid + the usual backtick result my ( $cmd ) = @_; my $pid = open my $ph, '-|', $cmd or die "$!: $cmd"; local $/ = undef(); my $backtick = <$ph>; close $ph; return ( $pid, $backtick ); }
Also, you don't have to wait for the command to finish because close does that for you.
|
|---|