perldoc.perl.org_IPC__Open2
perldoc.perl.org_IPC__Open2
Snapshot-Content-Location: https://perldoc.perl.org/IPC::Open2.txt
Subject:
Date: Thu, 13 Feb 2025 12:17:10 -0700
MIME-Version: 1.0
Content-Type: multipart/related;
type="text/html";
boundary="----MultipartBoundary--
AmrRLhumpbZLQ6XEVQlHpNNgs00MeBtf8FDkmpsiD7----"
------MultipartBoundary--AmrRLhumpbZLQ6XEVQlHpNNgs00MeBtf8FDkmpsiD7----
Content-Type: text/html
Content-ID: <[email protected]>
Content-Transfer-Encoding: binary
Content-Location: https://perldoc.perl.org/IPC::Open2.txt
use strict;
require 5.006;
use Exporter 'import';
=head1 NAME
IPC::Open2 - open a process for both reading and writing using open2()
=head1 SYNOPSIS
use IPC::Open2;
=head1 DESCRIPTION
The open2() function runs the given command and connects $chld_out for
reading and $chld_in for writing. It's what you think should work
when you try
my $pid = open(my $fh, "|cmd args|");
open2() does not wait for and reap the child process after it exits.
Except for short programs where it's acceptable to let the operating system
take care of this, you need to do this yourself. This is normally as
simple as calling C<waitpid $pid, 0> when you're done with the process.
Failing to do this can result in an accumulation of defunct or "zombie"
processes. See L<perlfunc/waitpid> for more information.
The big problem with this approach is that if you don't have control
over source code being run in the child process, you can't control
what it does with pipe buffering. Thus you can't just open a pipe to
C<cat -v> and continually read and write a line from it.
The L<IO::Pty> and L<Expect> modules from CPAN can help with this, as
they provide a real tty (well, a pseudo-tty, actually), which gets you
back to line buffering in the invoked command again.
=head1 WARNING
=cut
require IPC::Open3;
sub open2 {
local $Carp::CarpLevel = $Carp::CarpLevel + 1;
return IPC::Open3::_open3('open2', $_[1], $_[0], '>&STDERR', @_[2 ..
$#_]);
}
1
</pre></body></html>
------MultipartBoundary--AmrRLhumpbZLQ6XEVQlHpNNgs00MeBtf8FDkmpsiD7------