use IPC::Open3;
local(*A, *B, *C);
my $cmd = \&run;
my @args = ();
my $childpid = open3(*A, *B, *C, $cmd, @args);
print A "stuff\n";
close(A);
my @outlines = <B>;
my @errlines = <C>;
print "STDOUT:\n", @outlines, "\n";
print "STDERR:\n", @errlines, "\n";
close B;
close C;
waitpid($childpid, 0);
if ($?) {
print "That child exited with wait status of $?\n";
}
sub run {
}
It’s reporting:
STDERR:
sh: -c: line 0: syntax error near unexpected token `0x67bc50'
sh: -c: line 0: `CODE(0x67bc50)'
Why?
Looks like
$cmdshould be an actual shell command, not a perl subroutine. The error message comes from perl trying to execute the stringified reference to the sub,CODE(0x67bc50)in the shell.To get the return value from the subroutine as the command, use
$cmd->(). That might not do what I think you expect it to, though.