Correct me if I'm wrong, but the example you're trying to run is this one:
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;
}
|