On Tue, Aug 21, 2012 at 1:56 PM, Antoine P. <[email protected]> wrote:
> When I try to echo a simple ping localhost with the same script :
> I have a different output with annoying added line feeds which
> are not visible in a regular command line :
This likely has to do with Windows programs using \r\n as line
termination. Executing the Windows ping.exe:
irb(main):001:0> x=IO.popen ['/cygdrive/c/Windows/system32/ping',
'www.google.de'], 'r' do |io| io.read end
=> "\r\nPinging www-cctld.l.google.com [173.194.69.94] with 32 bytes
of data:\r\nReply from 173.194.69.94: bytes=32 time=39ms
TTL=43\r\nReply from 173.194.69.94: bytes=32 time=38ms TTL=43\r\nReply
from 173.194.69.94: bytes=32 time=38ms TTL=43\r\nReply from
173.194.69.94: bytes=32 time=40ms TTL=43\r\n\r\nPing statistics for
173.194.69.94:\r\n Packets: Sent = 4, Received = 4, Lost = 0 (0%
loss),\r\nApproximate round trip times in milli-seconds:\r\n
Minimum = 38ms, Maximum = 40ms, Average = 38ms\r\n"
irb(main):002:0> x.each_line.to_a
=> ["\r\n", "Pinging www-cctld.l.google.com [173.194.69.94] with 32
bytes of data:\r\n", "Reply from 173.194.69.94: bytes=32 time=39ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=38ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=38ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=40ms
TTL=43\r\n", "\r\n", "Ping statistics for 173.194.69.94:\r\n", "
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\n",
"Approximate round trip times in milli-seconds:\r\n", " Minimum =
38ms, Maximum = 40ms, Average = 38ms\r\n"]
irb(main):003:0> x.each_line("\r\n").to_a
=> ["\r\n", "Pinging www-cctld.l.google.com [173.194.69.94] with 32
bytes of data:\r\n", "Reply from 173.194.69.94: bytes=32 time=39ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=38ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=38ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=40ms
TTL=43\r\n", "\r\n", "Ping statistics for 173.194.69.94:\r\n", "
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\n",
"Approximate round trip times in milli-seconds:\r\n", " Minimum =
38ms, Maximum = 40ms, Average = 38ms\r\n"]
irb(main):004:0> x.each_line("\n").to_a
=> ["\r\n", "Pinging www-cctld.l.google.com [173.194.69.94] with 32
bytes of data:\r\n", "Reply from 173.194.69.94: bytes=32 time=39ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=38ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=38ms
TTL=43\r\n", "Reply from 173.194.69.94: bytes=32 time=40ms
TTL=43\r\n", "\r\n", "Ping statistics for 173.194.69.94:\r\n", "
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\n",
"Approximate round trip times in milli-seconds:\r\n", " Minimum =
38ms, Maximum = 40ms, Average = 38ms\r\n"]
irb(main):005:0> x=IO.popen ['/cygdrive/c/Windows/system32/ping',
'www.google.de'], 'r' do |io| io.each {|l| p l} end
"\r\n"
"Pinging www-cctld.l.google.com [173.194.69.94] with 32 bytes of data:\r\n"
"Reply from 173.194.69.94: bytes=32 time=40ms TTL=43\r\n"
"Reply from 173.194.69.94: bytes=32 time=40ms TTL=43\r\n"
"Reply from 173.194.69.94: bytes=32 time=40ms TTL=43\r\n"
"Reply from 173.194.69.94: bytes=32 time=39ms TTL=43\r\n"
"\r\n"
"Ping statistics for 173.194.69.94:\r\n"
" Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),\r\n"
"Approximate round trip times in milli-seconds:\r\n"
" Minimum = 39ms, Maximum = 40ms, Average = 39ms\r\n"
=> #<IO:(closed)>
Note, this is with 1.9 installed from sources.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en