diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-07-11 18:21:19 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-07-11 18:21:19 +0000 |
commit | 6662521eef19f96de52b97fb5fa07a85826679ee (patch) | |
tree | 3445a5d5bc8939118a426b52b520e63e7fe5035c /lib/IPC | |
parent | 7fdcfa2fc732bf742f6e1c2b723ab188bf8dc010 (diff) | |
download | perl-6662521eef19f96de52b97fb5fa07a85826679ee.tar.gz |
integrate cfgperl changes#6242..6249 into mainline
p4raw-link: @6249 on //depot/cfgperl: cab27d238e930b8cddb5b1fb3260355f913b86a6
p4raw-link: @6242 on //depot/cfgperl: 1e72252ad7b8e23d1a1142285b8aa82986bd2491
p4raw-id: //depot/perl@6359
p4raw-integrated: from //depot/cfgperl@6358 'copy in'
ext/DynaLoader/DynaLoader_pm.PL (@5953..) t/lib/peek.t
(@6086..) t/lib/filefunc.t t/lib/filespec.t (@6230..)
pod/perlintern.pod (@6237..) pod/perlapi.pod utf8.c (@6242..)
p4raw-integrated: from //depot/cfgperl@6249 'copy in' lib/IPC/Open3.pm
(@5937..)
p4raw-integrated: from //depot/cfgperl@6248 'copy in' pod/perlfunc.pod
(@6206..)
p4raw-integrated: from //depot/cfgperl@6247 'ignore' lib/File/Spec.pm
(@6230..)
p4raw-integrated: from //depot/cfgperl@6244 'copy in' gv.c (@6217..)
'merge in' sv.c (@6196..)
p4raw-integrated: from //depot/cfgperl@6243 'copy in' pp_proto.h
(@6237..) 'ignore' embedvar.h perlapi.h (@6237..) 'merge in'
embed.h objXSUB.h (@6237..) embed.pl perlapi.c proto.h
(@6242..)
Diffstat (limited to 'lib/IPC')
-rw-r--r-- | lib/IPC/Open3.pm | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/IPC/Open3.pm b/lib/IPC/Open3.pm index 46ebd68cef..6d91c81381 100644 --- a/lib/IPC/Open3.pm +++ b/lib/IPC/Open3.pm @@ -84,6 +84,7 @@ The order of arguments differs from that of open2(). # fixed for 5.001 by Ulrich Kunitz <kunitz@mai-koeln.com> # ported to Win32 by Ron Schmidt, Merrill Lynch almost ended my career # fixed for autovivving FHs, tchrist again +# allow fd numbers to be used, by Frank Tobin # # $Id: open3.pl,v 1.1 1993/11/23 06:26:15 marc Exp $ # @@ -136,6 +137,16 @@ sub xclose { close $_[0] or croak "$Me: close($_[0]) failed: $!"; } +sub xfileno { + my ($fh) = @_; + return $1 if $fh =~ /^=?(\d+)$/; # deal with $fh just being an fd + return fileno $fh; +} + +sub fh_is_fd { + return $_[0] =~ /^=?\d+$/; +} + my $do_spawn = $^O eq 'os2' || $^O eq 'MSWin32'; sub _open3 { @@ -164,9 +175,9 @@ sub _open3 { $dup_err = ($dad_err =~ s/^[<>]&//); # force unqualified filehandles into caller's package - $dad_wtr = qualify $dad_wtr, $package; - $dad_rdr = qualify $dad_rdr, $package; - $dad_err = qualify $dad_err, $package; + $dad_wtr = qualify $dad_wtr, $package unless fh_is_fd($dad_wtr); + $dad_rdr = qualify $dad_rdr, $package unless fh_is_fd($dad_rdr); + $dad_err = qualify $dad_err, $package unless fh_is_fd($dad_err); my $kid_rdr = gensym; my $kid_wtr = gensym; @@ -181,20 +192,20 @@ sub _open3 { # If she wants to dup the kid's stderr onto her stdout I need to # save a copy of her stdout before I put something else there. if ($dad_rdr ne $dad_err && $dup_err - && fileno($dad_err) == fileno(STDOUT)) { + && xfileno($dad_err) == fileno(STDOUT)) { my $tmp = gensym; xopen($tmp, ">&$dad_err"); $dad_err = $tmp; } if ($dup_wtr) { - xopen \*STDIN, "<&$dad_wtr" if fileno(STDIN) != fileno($dad_wtr); + xopen \*STDIN, "<&$dad_wtr" if fileno(STDIN) != xfileno($dad_wtr); } else { xclose $dad_wtr; xopen \*STDIN, "<&=" . fileno $kid_rdr; } if ($dup_rdr) { - xopen \*STDOUT, ">&$dad_rdr" if fileno(STDOUT) != fileno($dad_rdr); + xopen \*STDOUT, ">&$dad_rdr" if fileno(STDOUT) != xfileno($dad_rdr); } else { xclose $dad_rdr; xopen \*STDOUT, ">&=" . fileno $kid_wtr; @@ -204,8 +215,8 @@ sub _open3 { # I have to use a fileno here because in this one case # I'm doing a dup but the filehandle might be a reference # (from the special case above). - xopen \*STDERR, ">&" . fileno $dad_err - if fileno(STDERR) != fileno($dad_err); + xopen \*STDERR, ">&" . xfileno($dad_err) + if fileno(STDERR) != xfileno($dad_err); } else { xclose $dad_err; xopen \*STDERR, ">&=" . fileno $kid_err; |