in reply to Non-buffered read from program

Check out IO::Select, which does what you want.

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Replies are listed 'Best First'.
Re^2: Non-buffered read from program
by arc_of_descent (Hermit) on Dec 30, 2005 at 15:23 UTC

    IO::Select seems like a good choice, but unfortunately it does not work. i.e. if the whois server is unavailable, I get no output.

    open my $WHOIS, "jwhois x.x.x.x 2>&1 |"; my $s = IO::Select->new($WHOIS); while (my @ready = $s->can_read) { for my $fh (@ready) { if ($fh == $WHOIS) { my $buf = <$fh>; if ($buf) { print $buf; } else { close($fh); } } } }

    Note that this works great, if the server sends some output and then closes the connection, but not for servers which send some output and then hang.


    --
    Rohan