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!


In reply to IPC::Open3 misbehaving when STDOUT is not FD #1 by sgifford

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.