Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPC::Open3: fix dup example in synopsis #22615

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ext/IPC-Open3/lib/IPC/Open2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use strict;
require 5.006;
use Exporter 'import';

our $VERSION = 1.06;
our @EXPORT = qw(open2);
our $VERSION = 1.07;
our @EXPORT = qw(open2);

=head1 NAME

Expand All @@ -22,12 +22,12 @@ IPC::Open2 - open a process for both reading and writing using open2()
my $pid = open2(my $chld_out, my $chld_in, 'some cmd and args');

# read from parent STDIN and write to already open handle
open my $outfile, '>', 'outfile.txt' or die "open failed: $!";
my $pid = open2($outfile, '<&STDIN', 'some', 'cmd', 'and', 'args');
open OUTFILE, '>', 'outfile.txt' or die "open failed: $!";
my $pid = open2('>&OUTFILE', '<&STDIN', 'some', 'cmd', 'and', 'args');

# read from already open handle and write to parent STDOUT
open my $infile, '<', 'infile.txt' or die "open failed: $!";
my $pid = open2('>&STDOUT', $infile, 'some', 'cmd', 'and', 'args');
open INFILE, '<', 'infile.txt' or die "open failed: $!";
my $pid = open2('>&STDOUT', '<&INFILE', 'some', 'cmd', 'and', 'args');

# reap zombie and retrieve exit status
waitpid( $pid, 0 );
Expand Down
23 changes: 14 additions & 9 deletions ext/IPC-Open3/lib/IPC/Open3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use Exporter 'import';
use Carp;
use Symbol qw(gensym qualify);

our $VERSION = '1.22';
our @EXPORT = qw(open3);
our $VERSION = '1.23';
our @EXPORT = qw(open3);

=head1 NAME

Expand All @@ -26,8 +26,8 @@ IPC::Open3 - open a process for reading, writing, and error handling using open3

# read from parent STDIN
# send STDOUT and STDERR to already open handle
open my $outfile, '>>', 'output.txt' or die "open failed: $!";
my $pid = open3('<&STDIN', $outfile, undef,
open OUTFILE, '>>', 'output.txt' or die "open failed: $!";
my $pid = open3('<&STDIN', '>&OUTFILE', undef,
'some', 'cmd', 'and', 'args');

# write to parent STDOUT and STDERR
Expand All @@ -49,11 +49,16 @@ cannot be used for the STDERR filehandle, but gensym from L<Symbol> can
be used to vivify a new glob reference, see L</SYNOPSIS>. The $chld_in
will have autoflush turned on.

If $chld_in begins with C<< <& >>, then $chld_in will be closed in the
parent, and the child will read from it directly. If $chld_out or
$chld_err begins with C<< >& >>, then the child will send output
directly to that filehandle. In both cases, there will be a L<dup(2)>
instead of a L<pipe(2)> made.
If $chld_in begins with C<< <& >> followed by the name of a bareword
filehandle, then $chld_in will be closed in the parent, and the child
will read from it directly. If $chld_out or $chld_err begins with C<<
>& >>, then the child will send output directly to that filehandle. In
both cases, there will be a L<dup(2)> instead of a L<pipe(2)> made. In
other words, a string that starts with C<< <& >> or C<< >& >> acts like
an input parameter (i.e. open3() will simply pass the given handle on to
the child process) whereas normally handles act like output parameters
(i.e. open3() will create a pipe and place the respective read or write
end in the given parameter).

If either reader or writer is the empty string or undefined, this will
be replaced by an autogenerated filehandle. If so, you must pass a
Expand Down
Loading