unsubscribe


On Thu, Sep 5, 2013 at 9:05 AM, Jes=FAs Gabriel y Gal=E1n <
jgabrielygalan / gmail.com> wrote:

> On Thu, Sep 5, 2013 at 5:52 PM, Matthew Smith <lists / ruby-forum.com>
> wrote:
> > Here's my program:
> >
> > #!/usr/bin/ruby
> > target =3D "192.168.1.1"
> > ping_response =3D `ping -c1 -W1 #{target}`
> > puts "Ping response =3D " + ping_response
> >
> > When I run it, I get:
> >
> > <--- Start output
> > Response =3D PING 192.168.1.1 (192.168.1.1 56(84) bytes of data.
> >
> > --- 192.168.1.1 ping statistics ---
> > 1 packets transmitted, 0 received, 100% packet loss, time 0ms
> > ----> End output
> >
> > As you can see, the captured line isn't very helpful.
> >
> > When I run the ping command normally from the command line I get:
> > <--- Start output
> > PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
> > 64 bytes from 192.168.1.1: icmp_seq=3D1 ttl=3D64 time=3D0.055 ms
> >
> > --- 192.168.1.1 ping statistics ---
> > 1 packets transmitted, 1 received, 0% packet loss, time 0ms
> > rtt min/avg/max/mdev =3D 0.055/0.055/0.055/0.000 ms
> > ----> End output
> >
> >
> > I'd really like to capture the second line that has the response time i=
n
> > it.  I thought I could do so by grepping something that only it has:
> >
> > ping_response =3D `ping -c1 -W1 #{target} | grep seq`
> >
> > Now when I run the program I get:
> >
> > <--- Start output
> > Response =3D
> > ----> End output
> >
> >
> > Anyone know how to get this done?
> >
> > --
> > Posted via http://www.ruby-forum.com/.
>
> I'm not seeing the same as you:
>
> 2.0.0p195 :001 > output =3D `ping -c1 -W1 www.google.com`
>  =3D> [snip]
> 2.0.0p195 :002 > puts "ping response: #{output}"
> ping response: PING www.google.com (x.x.x.x) 56(84) bytes of data.
> 64 bytes from xxxxx (x.x.x.x): icmp_req=3D1 ttl=3D54 time=3D28.3 ms
>
> --- www.google.com ping statistics ---
> 1 packets transmitted, 1 received, 0% packet loss, time 0ms
> rtt min/avg/max/mdev =3D 28.335/28.335/28.335/0.000 ms
>  =3D> nil
> 2.0.0p195 :004 > output.split("\n")[1]
>  =3D> "64 bytes from xxxxxx (x.x.x.x): icmp_req=3D1 ttl=3D54 time=3D28.3 =
ms"
>
> So I do get that second line with the time.
>
> Jesus.
>