[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to read a PIPE in unbuffered way?

Iñaki Baz Castillo

9/24/2008 10:34:00 PM

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

=2D--------------------
open(PIPE,"ngrep dst port 80 |");
select(PIPE); $| =3D 1; # make unbuffered
select(STDOUT); $| =3D 1; # make unbuffered

while(<PIPE>)
{ =20
chomp($_);
s/
//ig;
s/ // if(/^ /);
#### process and change the captured data before writting to the screen ##=
##
}
close(PIPE);
=2D------------------------

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

I assume I must start with:

f =3D IO.popen("ngrep dst port 80")

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



=2D-=20
I=C3=B1aki Baz Castillo

3 Answers

robhurring

9/25/2008 3:58:00 PM

0

something like this?

IO.popen('ngrep dst port 80').each do |line|
# PROCESS LINE
end

ara.t.howard

9/25/2008 4:16:00 PM

0


On Sep 24, 2008, at 4:33 PM, I=F1aki Baz Castillo wrote:

> Hi, I'd like to know the Ruby equivalent to the following Perl code:
>
> ---------------------
> open(PIPE,"ngrep dst port 80 |");
> select(PIPE); $| =3D 1; # make unbuffered
> select(STDOUT); $| =3D 1; # make unbuffered
>
> while(<PIPE>)
> {
> chomp($_);
> s/
> //ig;
> s/ // if(/^ /);
> #### process and change the captured data before writting to the =
=20
> screen ####
> }
> close(PIPE);
> -------------------------
>
> "ngrep" itself is a Linux command that captures TCP/UDP data and =20
> prints it to
> the screen. In this case I capture traffic with destination port 80.
>
> I assume I must start with:
>
> f =3D IO.popen("ngrep dst port 80")
>
> but no idea of what to do after that. Any help please? Thanks a lot.
>
>
>
> --=20
> I=F1aki Baz Castillo
>

ammunition

require 'io/nonblock'


http://codeforp...lib/ruby/nbfifo/nbfifo-0....




a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being =20
better. simply reflect on that.
h.h. the 14th dalai lama




Iñaki Baz Castillo

9/25/2008 10:03:00 PM

0

El Jueves, 25 de Septiembre de 2008, robhurring@gmail.com escribi=F3:
> something like this?
>
> IO.popen('ngrep dst port 80').each do |line|
> # PROCESS LINE
> end

Great!
Thanks a lot.

=2D-=20
I=F1aki Baz Castillo