Correct me if I'm wrong, but the example you're trying to run is this one:

# example with IPC via pipe use strict; use IO::Pipe; use Proc::Fork; my $p = new IO::Pipe; parent { my $child = shift; $p->reader; print while ( <$p> ); waitpid $child,0; } child { $p->writer; print $p "Line 1\n"; print $p "Line 2\n"; exit; } retry { if( $_[0] < 5 ) { sleep 1; return 1; } return 0; } error { die "That's all folks\n"; };

This example works for me (after I install Proc::Fork).

The message you're getting (Can't locate object method "writer" via package "IO::Pipe::End") sounds to me as if IO::Pipe hasn't been loaded, but if that were the case, it should fail much earlier with the message: Can't locate object method "new" via package "IO::Pipe" (perhaps you forgot to load "IO::Pipe"?)

So I'm wondering if you've changed anything.

In general, when I want to run a child, I just use fork directly. For the kind of problem solved by the example, I use open with special '-|' second argument. For example:

# This forks implicitly my $child_pid = open my $child_fh, '-|'; if ( ! defined $child_pid ) { die "Can't fork: $!"; } if ( $child_pid ) { # parent print while ( <$child_fh> ); # this implicitly waits for the child close $child_fh or die "close on pipe failed: $!"; } else { # child # child's STDOUT is connected to the pipe print "Line 1\n"; print "Line 2\n"; exit; }

In reply to Re: IO:Pipe functioning by kyle
in thread IO:Pipe functioning by pepperl

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.