I'm attempting to write a wrapper for some external programs that I'll be calling from a Perl script.

I need to capture all the inputs and outputs - STDERR being the most important.

After looking through The Camel and around the Monastery, I found IPC::Open3.

I've already looked at the following nodes, but I'm still unable to get a script that performs as I expect:

For testing purposes I'm just using a simple Perl script as the command to be run by open3(), rather than using the binary. I've also tried using cat as well.
This script is as follows:

#!/usr/local/bin/perl # Test script to write to STDOUT # and STDERR. use warnings; use strict; print STDOUT "StdOut!\n"; print STDERR "StdErr!\n";

The main script (using IPC::Open3) is:

#!/usr/local/bin/perl # Script to test IPC::Open3 # Runs, displays $pid to STDOUT, but opened # files are empty. use strict; use warnings; use diagnostics; use IPC::Open3; $|++; my $cmd = "/home/baz/test.pl"; open(ERRLOG, ">error.log") or die "Can't open error log! $!"; open(OUTPUT, ">output.log") or die "Can't open output log! $!"; my $pid = open3(\*STDIN, \*OUTPUT, \*ERRLOG, $cmd) or die "$!"; print "PID was $pid\n"; close(ERRLOG) or die "Can't close filehandle! $!"; close(OUTPUT) or die "Can't close filehandle! $!";
I'm expecting this script to write the output from my test.pl script to output.log and errors from the test script to error.log, however both files are created, but empty.

Have I got the wrong end of the stick somewhere?


In reply to IPC::Open3 woes by BazB

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.