Front page | perl.perl5.porters |
Postings from December 2011
[perl #31738] IPC::Open3 doesn't vivify an err filehandle
Thread Next
From:
James E Keenan via RT
Date:
December 2, 2011 16:31
Subject:
[perl #31738] IPC::Open3 doesn't vivify an err filehandle
Message ID:
rt-3.6.HEAD-5084-1322872310-387.31738-15-0@perl.org
On Mon Sep 27 07:05:23 2004, perl-5.8.0@ton.iguana.be wrote:
>
> perl -le '
> use IPC::Open3;
> my($wtr, $rdr, $err);
> $pid = open3($wtr, $rdr, $err, "echo");
> print "wtr=$wtr, rdr=$rdr, err=$err"
> '
>
> This outputs:
> wtr=GLOB(0x81622c0), rdr=GLOB(0x816208c), err=
>
> So as you can see $err actually never gets filled in.
> If you look in the code for IPC::Open3, sub _open3 you see that
> indeed $_[3] (which is where $err should get set) never gets
> assigned a value.
>
> Beyond that the logic also seems wrong for getting the err handle
> filled in:
>
> $dad_err ||= $dad_rdr;
>
> will duplicate $dad_rdr to $dad_err, which means that later the
>
> xpipe $dad_err, $kid_err if !$dup_err && $dad_err ne $dad_rdr;
>
> will do nothing. So stderr will not get its own pipe. And indeed
> stracing
> shows that only stdin and stdout get their own pipes.
>
> Possibly this is intentional, because the docs say:
>
> If either reader or writer is the null string, this will be
> replaced by
> an autogenerated filehandle. If so, you must pass a valid
> lvalue in
> the parameter slot so it can be overwritten in the caller, or
> an excep-
> tion will be raised.
>
> which indeed doesn't talk about $err (and it talks about empty strings
> and not undef really). But in that case the synopsis is completely
> misleading because that says:
>
> my($wtr, $rdr, $err);
> $pid = open3($wtr, $rdr, $err,
> 'some cmd and args', 'optarg', ...);
>
> which suggests $err is now something you can use instead of just a
> useless placeholder (you could just as well directly pass undef, it
> doesn't get assigned anyways). And in fact if you weren't interested
> in catching STDERR, you could just as well have used open2 instead of
> open3. So I think that a behaviour where $err gets its own pipe and
> gets filled in makes more sense.
>
> (Mmm, and why is the code playing ugly gensym games anyways now that
> we have autovivified filehandles ? E.g. at first sight it looks like
> the $kid gensym assigns can simply be dropped if the xpipe error
> message is modified to not refer to its arguments)
>
Confirmed that, seven years later, problem persists:
$ perl -le '
> use IPC::Open3;
> my($wtr, $rdr, $err);
> $pid = open3($wtr, $rdr, $err, "echo");
> print "wtr=$wtr, rdr=$rdr, err=$err"
> '
wtr=GLOB(0x1804100), rdr=GLOB(0x1804110), err=
Thank you very much.
Jim Keenan
Thread Next
-
[perl #31738] IPC::Open3 doesn't vivify an err filehandle
by James E Keenan via RT