Hello,
Here is a script that does what you wanted to to with enough comments to explain every step:
#!/usr/bin/perl -w # Script to test IPC::Open3 # Runs, displays $pid to STDOUT, but opened # files are empty. use strict; use warnings; use diagnostics; use IPC::Open3; use IO::Select; # for select use Symbol; # for gensym $|++; my $cmd = "./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 ($infh,$outfh,$errfh); # these are the FHs for our child $errfh = gensym(); # we create a symbol for the errfh # because open3 will not do that for us my $pid; eval{ $pid = open3($infh, $outfh, $errfh, $cmd); }; die "open3: $@\n" if $@; print "PID was $pid\n"; my $sel = new IO::Select; # create a select object to notify # us on reads on our FHs $sel->add($outfh,$errfh); # add the FHs we're interested in while(my @ready = $sel->can_read) { # read ready foreach my $fh (@ready) { my $line = <$fh>; # read one line from this fh if(not defined $line){ # EOF on this FH $sel->remove($fh); # remove it from the list next; # and go handle the next FH } if($fh == $outfh) { # if we read from the outfh print OUTPUT $line; # print it to OUTFH } elsif($fh == $errfh) {# do the same for errfh print ERRLOG $line; } else { # we read from something else?!?! die "Shouldn't be here\n"; } } } close(ERRLOG) or die "Can't close filehandle! $!"; close(OUTPUT) or die "Can't close filehandle! $!";
So, basically, open3 gives you the file handles that you can use to read from or write to the child process. It will not automatically pipe the output to a file as you thought. What you need to do is read from the file handles and print them to the files yourself.

Hope this helps,,,

Aziz,,,


In reply to Re: IPC::Open3 woes by abstracts
in thread 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.