How to read a PIPE in unbuffered way?

Hi, I’d like to know the Ruby equivalent to the following Perl code:


open(PIPE,“ngrep dst port 80 |”);
select(PIPE); $| = 1; # make unbuffered
select(STDOUT); $| = 1; # make unbuffered

while()
{
chomp($_);
s/
//ig;
s/ // if(/^ /);

process and change the captured data before writting to the

screen ####
}
close(PIPE);

“ngrep” itself is a Linux command that captures TCP/UDP data and prints
it to
the screen. In this case I capture traffic with destination port 80.

I assume I must start with:

f = IO.popen(“ngrep dst port 80”)

but no idea of what to do after that. Any help please? Thanks a lot.

something like this?

IO.popen(‘ngrep dst port 80’).each do |line|

PROCESS LINE

end

On Sep 24, 2008, at 4:33 PM, Iñaki Baz C. wrote:

   s/

the screen. In this case I capture traffic with destination port 80.
Iñaki Baz C.

ammunition

require ‘io/nonblock’

http://codeforpeople.com/lib/ruby/nbfifo/nbfifo-0.0.0/README

a @ http://codeforpeople.com/

El Jueves, 25 de Septiembre de 2008, [email protected]
escribió:> something like this?

IO.popen(‘ngrep dst port 80’).each do |line|

PROCESS LINE

end

Great!
Thanks a lot.