Skip to content

Commit 78005a3

Browse files
committed
IPC::Open3: fix dup example in synopsis
Unfortunately, this feature is based on parsing out filehandle names from strings, so it requires bareword filehandles to work. Try to make this clearer in the documentation and mention that arguments starting with `>&` or `<&` are input parameters (i.e. existing open handles to use) as opposed to regular output parameters (which open3 connects to newly created pipes). Fixes #22608.
1 parent 7eba715 commit 78005a3

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

ext/IPC-Open3/lib/IPC/Open2.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use strict;
55
require 5.006;
66
use Exporter 'import';
77

8-
our $VERSION = 1.06;
9-
our @EXPORT = qw(open2);
8+
our $VERSION = 1.07;
9+
our @EXPORT = qw(open2);
1010

1111
=head1 NAME
1212
@@ -22,12 +22,12 @@ IPC::Open2 - open a process for both reading and writing using open2()
2222
my $pid = open2(my $chld_out, my $chld_in, 'some cmd and args');
2323
2424
# read from parent STDIN and write to already open handle
25-
open my $outfile, '>', 'outfile.txt' or die "open failed: $!";
26-
my $pid = open2($outfile, '<&STDIN', 'some', 'cmd', 'and', 'args');
25+
open OUTFILE, '>', 'outfile.txt' or die "open failed: $!";
26+
my $pid = open2('>&OUTFILE', '<&STDIN', 'some', 'cmd', 'and', 'args');
2727
2828
# read from already open handle and write to parent STDOUT
29-
open my $infile, '<', 'infile.txt' or die "open failed: $!";
30-
my $pid = open2('>&STDOUT', $infile, 'some', 'cmd', 'and', 'args');
29+
open INFILE, '<', 'infile.txt' or die "open failed: $!";
30+
my $pid = open2('>&STDOUT', '<&INFILE', 'some', 'cmd', 'and', 'args');
3131
3232
# reap zombie and retrieve exit status
3333
waitpid( $pid, 0 );

ext/IPC-Open3/lib/IPC/Open3.pm

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use Exporter 'import';
88
use Carp;
99
use Symbol qw(gensym qualify);
1010

11-
our $VERSION = '1.22';
12-
our @EXPORT = qw(open3);
11+
our $VERSION = '1.23';
12+
our @EXPORT = qw(open3);
1313

1414
=head1 NAME
1515
@@ -26,8 +26,8 @@ IPC::Open3 - open a process for reading, writing, and error handling using open3
2626
2727
# read from parent STDIN
2828
# send STDOUT and STDERR to already open handle
29-
open my $outfile, '>>', 'output.txt' or die "open failed: $!";
30-
my $pid = open3('<&STDIN', $outfile, undef,
29+
open OUTFILE, '>>', 'output.txt' or die "open failed: $!";
30+
my $pid = open3('<&STDIN', '>&OUTFILE', undef,
3131
'some', 'cmd', 'and', 'args');
3232
3333
# write to parent STDOUT and STDERR
@@ -49,11 +49,16 @@ cannot be used for the STDERR filehandle, but gensym from L<Symbol> can
4949
be used to vivify a new glob reference, see L</SYNOPSIS>. The $chld_in
5050
will have autoflush turned on.
5151
52-
If $chld_in begins with C<< <& >>, then $chld_in will be closed in the
53-
parent, and the child will read from it directly. If $chld_out or
54-
$chld_err begins with C<< >& >>, then the child will send output
55-
directly to that filehandle. In both cases, there will be a L<dup(2)>
56-
instead of a L<pipe(2)> made.
52+
If $chld_in begins with C<< <& >> followed by the name of a bareword
53+
filehandle, then $chld_in will be closed in the parent, and the child
54+
will read from it directly. If $chld_out or $chld_err begins with C<<
55+
>& >>, then the child will send output directly to that filehandle. In
56+
both cases, there will be a L<dup(2)> instead of a L<pipe(2)> made. In
57+
other words, a string that starts with C<< <& >> or C<< >& >> acts like
58+
an input parameter (i.e. open3() will simply pass the given handle on to
59+
the child process) whereas normally handles act like output parameters
60+
(i.e. open3() will create a pipe and place the respective read or write
61+
end in the given parameter).
5762
5863
If either reader or writer is the empty string or undefined, this will
5964
be replaced by an autogenerated filehandle. If so, you must pass a

0 commit comments

Comments
 (0)