I need to split up stdout and stderr from a shell process i am executing in perl. I went down the path of using CaptureOutput perl module to accomplish my objective. I am now having problems with the Success flag if I am in a child process with $SIG{CHLD} = 'IGNORE'; set. Please see my sample below and let me know if there is anything that I could do to make this process return success like it should. If not is there another way to handle getting stdout and stderr into different scalars that would be 100% reliable?
#!/usr/bin/perl use Data::Dumper; use IO::CaptureOutput qw/capture_exec/; # The first test shows the Success = 1 &runCommand(); # Now the same thing in a child process shows Success = 1 unless ( $pid = fork ) { &runCommand(); exit; } # Now child process with IGNORE set, shows Success = 0 $SIG{CHLD} = 'IGNORE'; unless ( $pid = fork ) { &runCommand(); exit; } sub runCommand { ($stdout, $stderr, $success, $exit_code) = capture_exec('perl', '- +e', 'print "Test"'); print "stdout: $stdout\n"; print "stderr: $stderr\n"; print "Success: $success\n"; print "exit code: $exit_code\n"; }
Thanks

In reply to Using IO::CaptureOutput in a child process to caputre STDOUT and STDERR by clintonm9

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.