On Aug 28, 10:42 pm, ole...@gmail.com (marcos rebelo) wrote:
> the idea is to process the STDOUT ad the STDERR.
>
> open don't do it
>

I was afraid you'd say that...

open3 is very liable to deadlock since you're trying to read from
both stderr and stdout.  You'll very likely want to use IO::Select
to marshal when the read's occur and search for some sample
code.

>
> On Sun, Aug 29, 2010 at 6:08 AM, John W. Krahn <jwkr...@shaw.ca> wrote:
>
>
>
> > C.DeRykus wrote:
>
> >> Since you mention simplifying the code, do you actually
> >> need IPC::Open3 ?  In your sample code, you're only
> >> reading process output.
>
> >> If you don't need IPC::Open3 complexity, you could just
> >> use magic open to read output :
>
> >> sub shell_run
> >> {
> >>     print "YYYY";
> >>     my $pid = open( my $fh, qq{ @_ | } )  or die "open: $!";
>
> > Probably better as:
>
> >      my $pid = open my $fh, '-|', @_ or die "open: $!";


In general yes but here I don't think there's a benefit.
I believe perl will bypass  the shell in both cases since
a list is passed. And, IIRC,  perl launches a shell only
after parsing to see if it's absolutely required.


>
> > And you don't use $pid anywhere so why create it?

Agreed, I was trying to guage the OP's intention more
than cleaning up all the code.

>
> >>     print for<$fh>;
>
> > Probably better as:
>
> >      print while <$fh>;

Hm, I'd prefer 'while' as well but, though it may look odd, I
don't think there's been the  penalty of 'for <$fh>' creating
and then iterating  through a potentially large list  for some
time.

>
> >>     close $fh  or die "close: ", $? || $!;
>
> > Probably better as:
>
> >      close $fh or die $! ? "Error closing pipe: $!"
> >                          : "Exit status $? from $_[0]";

Definitely better. A child error might mask an
error for a full disk.

--
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to