Skip Menu |

This queue is for tickets about the IPC-Run3 CPAN distribution.

Report information
The Basics
Id: 57391
Status: open
Priority: 0/
Queue: IPC-Run3

People
Owner: RSCHUPP [...] cpan.org
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: errors sent to STDOUT
Date: Wed, 12 May 2010 07:39:24 +1000
To: bug-IPC-Run3 [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
While nosing around IPC::Run3 0.043_02 I wondered how the handle duping would go if permuting stdin/out/err. The program errout.pl below writes 'blah' to /tmp/xxx, whereas I think I hoped it would write to the tty (ie. the parent's STDOUT). The "sh -c" is just a program which writes to its stderr. Replace it with something simpler as desired. It might be reasonably easy to dup from SAVED_STDOUT when the child's stderr is the parent's stdout. A fully general thing would allow for all three of stdin/out/err to be mixed around. It wouldn't often make much sense to put STDIN as a child's stdout or stderr, but I think it'd be worth doing correctly so as to get the right kind of error out of the child and/or simply to ensure it doesn't operate on the wrong thing.
use strict; use warnings; use IPC::Run3; print IPC::Run3->VERSION,"\n"; open MYFILE, '>/tmp/xxx' or die; run3 (['sh','-c','echo blah >&2'], \undef, \*MYFILE, \*STDOUT);
On Tue May 11 17:40:52 2010, user42@zip.com.au wrote: Show quoted text
> While nosing around IPC::Run3 0.043_02 I wondered how the handle duping > would go if permuting stdin/out/err.
Good catch. I'm not sure how to fix this in the general case. As a fist step, I created a new test that will call run3() with all six possible permutations of STDIN, STDOUT and STDERR (regardless how likely such a use case is). Fails miserably, of course. Cheers, Roderich
Subject: Re: [rt.cpan.org #57391] errors sent to STDOUT
Date: Tue, 18 May 2010 10:09:47 +1000
To: bug-IPC-Run3 [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"RSCHUPP via RT" <bug-IPC-Run3@rt.cpan.org> writes: Show quoted text
> > I'm not sure how to fix this in the general case.
If you've made local dups saving the handles anyway then it might work to re-dup off those. Something like (untested) my @dups = (fileno(SAVED_STDIN), fileno(SAVED_STDOUT), fileno(SAVED_STDERR)); # map a target $fd through @dups if (exists $dups[$fd]) { $fd = $dups[$fd]; } Driving it from the fd (like you've got now) would I think pick up any handle which is an IO::Handle->new_from_fd referring to 0, 1 or 2 in addition to the real STDIN/OUT/ERR handles.
On Mon May 17 20:10:54 2010, user42@zip.com.au wrote: Show quoted text
> If you've made local dups saving the handles anyway then it might work > to re-dup off those. Something like (untested)
Good idea. I had a much more complex solution. This passes the new "permute STD* filehandles" torture test. I'll do a developer release tonite. BTW if you have some tuits to spare, uncomment the failing t/zz_pipe*.t tests at the end of Makefile.PL. I have absolutely no clue how to fix these or what's the difference when reading from a file script.pl < file instead of from a pipe cat file | script.pl The bug here is that when script.pl calls run3() in the middle of reading STDIN, parts of the input get lost. Cheers, Roderich
Subject: Re: [rt.cpan.org #57391] errors sent to STDOUT
Date: Tue, 08 Jun 2010 10:38:37 +1000
To: bug-IPC-Run3 [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"RSCHUPP via RT" <bug-IPC-Run3@rt.cpan.org> writes: Show quoted text
> > The bug here is that when script.pl calls run3() in the middle > of reading STDIN, parts of the input get lost.
Hmm. I see the problem. It looks like the "open STDIN <&" discards the input buffer on the STDIN handle and because a pipe is not seekable it can't re-read like on an ordinary file. I suppose the local dup is not doing enough to preserve the underlying IO object. Dunno what the right thing to do would be. Try to squirrel away the *STDIN{IO} object or something. Or try to dig out the input buffer contents and unget them back onto the handle afterwards (for non-seekable inputs). That might be unfriendly or unworkable with layers though ...
Subject: Re: [rt.cpan.org #57391] errors sent to STDOUT
Date: Tue, 08 Jun 2010 11:15:50 +1000
To: bug-IPC-Run3 [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
I wrote: Show quoted text
> > looks like the "open STDIN <&"
I suppose only the file descriptors matter to the system() call. Maybe "flushall" the same way it will and then temporarily POSIX::dup2() the desired fds to 0,1,2 as necessary.