Admittedly, my first response was on the fly, but I dug deeper and tried this:

#!/usr/bin/perl use strict; use warnings; use diagnostics; use IPC::Open3; use POSIX 'setsid'; sub daemonize { chdir '/' or die "Can't chdir to /: $!"; open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; defined( my $pid = fork ) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; } open( SAVE_STDOUT, ">&", STDOUT ) or die "save stdout failed"; open( DEVNULL, "< /dev/null" ) or die "open /dev/null failed"; open( FH1, "> /dev/null" ) or die "Open /dev/null failed"; &daemonize( *FH1 ); open3( *DEVNULL, *PIPE, undef, "/bin/sh", "-c", <<EOF ); printf "out 1\\nout 2\\nout 3\\n" printf "err 1\\nerr 2\\nerr 3\\n" >&2 EOF ; open( STDOUT, ">&", *SAVE_STDOUT ) or die "restore stdout failed: $!"; while(<PIPE>) { print "PIPE: ", $_; } close(PIPE) or die "close pipe failed"; exit(1);

In reply to Re: IPC::Open3 misbehaving when STDOUT is not FD #1 by Khen1950fx
in thread 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.