IO::Pipe(3perl) Perl Programmers Reference Guide IO::Pipe(3perl)

IO::Pipe - supply object methods for pipes

use IO::Pipe;
$pipe = IO::Pipe->new();
if($pid = fork()) { # Parent
    $pipe->reader();
    while(<$pipe>) {
        ...
    }
}
elsif(defined $pid) { # Child
    $pipe->writer();
    print $pipe ...
}
or
$pipe = IO::Pipe->new();
$pipe->reader(qw(ls -l));
while(<$pipe>) {
    ...
}

"IO::Pipe" provides an interface to creating pipes between processes.

Creates an "IO::Pipe", which is a reference to a newly created symbol (see the Symbol package). "IO::Pipe::new" optionally takes two arguments, which should be objects blessed into "IO::Handle", or a subclass thereof. These two objects will be used for the system call to "pipe". If no arguments are given then method "handles" is called on the new "IO::Pipe" object.

These two handles are held in the array part of the GLOB until either "reader" or "writer" is called.

The object is re-blessed into a sub-class of "IO::Handle", and becomes a handle at the reading end of the pipe. If "ARGS" are given then "fork" is called and "ARGS" are passed to exec.
The object is re-blessed into a sub-class of "IO::Handle", and becomes a handle at the writing end of the pipe. If "ARGS" are given then "fork" is called and "ARGS" are passed to exec.
This method is called during construction by "IO::Pipe::new" on the newly created "IO::Pipe" object. It returns an array of two objects blessed into "IO::Pipe::End", or a subclass thereof.

IO::Handle

Graham Barr. Currently maintained by the Perl Porters. Please report all bugs at https://github.com/Perl/perl5/issues.

Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2024-02-11 perl v5.38.2