|
Posted by Ben Morrow on May 6, 2008, 6:59 pm
Please log in for more thread options
Quoth ddunham@taos.com (Darren Dunham):
> xhoster@gmail.com wrote:
> > ddunham@taos.com (Darren Dunham) 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
|