Subject: | '&' closing the stdin of the wrong process |
According to the pod:
Child processes to the right of a '&' will have their stdin closed
unless it's redirected-to.
It actually closes the stdin of the process to the left overriding a
piped stdin
e.g. in A | B & C
B has its stdin first connected to the pipe from A, but then it is closed.
C's stdin remains unaffected.
Attached is a hack I am using locally.
Subject: | Run.pm.patch |
--- lib/IPC/Run.pm
+++ lib/IPC/Run.pm
@@ -1676,6 +1676,7 @@
# if an op is seen.
my $cur_kid; # references kid or handle being parsed
+ my $next_kid_close_stdin = 0;
my $assumed_fd = 0; # fd to assume in succinct mode (no redir ops)
my $handle_num = 0; # 1... is which handle we're parsing
@@ -1731,6 +1732,11 @@
PID => '',
RESULT => undef,
};
+ unshift @{$cur_kid->{OPS}}, {
+ TYPE => 'close',
+ KFD => 0,
+ } if $next_kid_close_stdin;
+ $next_kid_close_stdin = 0;
push @{$self->{KIDS}}, $cur_kid;
$succinct = 1;
}
@@ -1949,10 +1955,7 @@
elsif ( $_ eq "&" ) {
croak "No command before '$_'" unless $cur_kid;
- unshift @{$cur_kid->{OPS}}, {
- TYPE => 'close',
- KFD => 0,
- };
+ $next_kid_close_stdin = 1 ;
$succinct = 1;
$assumed_fd = 0;
$cur_kid = undef;