http://qs321.pair.com?node_id=768840

sgifford has asked for the wisdom of the Perl Monks concerning the following question:

I'm having some trouble with IPC::Open3. Here is a test script that demonstrates the problem:
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; # Basic setup stuff open(SAVE_STDOUT,">&",STDOUT) or die "save stdout failed"; open(DEVNULL,"< /dev/null") or die "open /dev/null failed"; # Now set STDOUT to a filehandle on a new descriptor open(FH1,"> /dev/null") or die "open /dev/null failed"; *STDOUT = *FH1; # Run the command open3(*DEVNULL, *PIPE, undef, "/bin/sh","-c",<<EOF) or die "open3 fail +ed"; printf "out 1\\nout 2\\nout 3\\n" printf "err 1\\nerr 2\\nerr 3\\n" >&2 EOF ; # And copy the output open(STDOUT,">&",*SAVE_STDOUT) or die "restore stout failed"; while (<PIPE>) { print "PIPE: ",$_; } close(PIPE) or die "close pipe failed"; exit(0);
The expected output from this is:
PIPE: out 1 PIPE: out 2 PIPE: out 3 PIPE: err 1 PIPE: err 2 PIPE: err 3
which indicates that the child process had both standard output and standard error sent to the pipe created by open3. Instead, with both IPC::Open3 1.02 and 1.03, I get this output:
out 1 out 2 out 3 PIPE: err 1 PIPE: err 2 PIPE: err 3
This indicates that the standard output from the script didn't go through the pipe. Instead it went directly to my terminal, where file descriptor #1 is connected to in the parent process.

This appears to be the result of a bug in IPC::Open3, which I reported in Perl bug #66224, including a patch. I wanted to see if my fellow Monks had any insight or ideas for a better fix/workaround.

Thanks!