|
From: Ben Morrow on 6 May 2008 18:59 Quoth ddunham(a)taos.com (Darren Dunham): > xhoster(a)gmail.com wrote: > > ddunham(a)taos.com (Darren Dunham) wrote: > >> Ben Morrow <ben(a)morrow.me.uk> wrote: > >> > I would normally say 'Use lexical filehandles!' at this point; > >> > unfortunately, IPC::Open3 was written before they existed and the > >> > obvious way > >> > > >> > my $pid = open3(my $CMD_IN, my $CMD_OUT, my $CMD_ERR, @cmd)... > >> > > >> > doesn't work (and can't be made to since undef is already meaningful). > >> > >> What's wrong with the above? > > > > It causes cmd's stderr to go to $CMD_OUT rather than the obviously > > intended $CMD_ERR. > > I don't know that it's obviously intended. It took me quite a while to > realize that I even had an option to return output and error on a single > filehandle. I mention that explicitly because the OP might have been > having issues with selecting between the two, when reading them combined > may have been preferable. > > However, if you do want them separated, then the other choices offered > seem quite verbose. Instead of them, I would pass in a (defined) > filehandle. That takes one more line of code (two if you count bringing > in the FileHandle module. > > my $CMD_ERR = FileHandle->new(); > my $pid = open3(my $CMD_IN, my $CMD_OUT, $CMD_ERR, @cmd)... ....which is essentially the same as what I proposed, except that I prefer to avoid FileHandle (and IO::Handle) and use Symbol::gensym directly. That's just a matter of taste, of course. Ben
From: Ilya Zakharevich on 6 May 2008 20:04 [A complimentary Cc of this posting was NOT [per weedlist] sent to Ben Morrow <ben(a)morrow.me.uk>], who wrote in article <jtb6f5-qg1.ln1(a)osiris.mauzo.dyndns.org>: > > sub open3 ($$$$@) { > > $_[0] = IO::Handle->new unless defined $_[0]; # Or whatever is THE > > initializer > > ... > > } > Yeah, in general you can do that; however, for the specific case of > open3, the docs say > > If CHLD_ERR is false, or the same file descriptor as CHLD_OUT, then > STDOUT and STDERR of the child are on the same filehandle. Thanks, I forgot about this semantic. Which does not mean that one could not write ALSO open3_autovivify... ;-) Yours, Ilya
|
Pages: 1 Prev: master perl calling slave perl Next: FAQ 4.17 How do I find yesterday's date? |