My first post here, I'm newbie in ruby, maybe somebody could help me
with this.
I have a script that read/parse a binary file. The scripts works fine if
I run it in Ubuntu, but I'm trying
to run the code in IRB on Windows7 with Ruby version "2.0.0p247
(2013-06-27) [i386-mingw32]" and I receive
the following errors.
···
##########################################################################
C:\Scripts>ruby script.rb binaryfile
script.rb:18:in `gets': encoding mismatch: CP850 IO with UTF-8 RS
(ArgumentError)
from script.rb:18:in `gets'
from script.rb:18:in `<main>'
##########################################################################
The script is like below (line 18 contains while gets):
On Fri, Sep 13, 2013 at 5:16 PM, Sever Siller <lists@ruby-forum.com> wrote:
Hello to all in forum,
My first post here, I'm newbie in ruby, maybe somebody could help me
with this.
I have a script that read/parse a binary file. The scripts works fine if
I run it in Ubuntu, but I'm trying
to run the code in IRB on Windows7 with Ruby version "2.0.0p247
(2013-06-27) [i386-mingw32]" and I receive
the following errors.
##########################################################################
C:\Scripts>ruby script.rb binaryfile
script.rb:18:in `gets': encoding mismatch: CP850 IO with UTF-8 RS
(ArgumentError)
from script.rb:18:in `gets'
from script.rb:18:in `<main>'
##########################################################################
The script is like below (line 18 contains while gets):
Thank you for your answers. I'll your suggestions.
I try to use "while gets" because the binary is divided by blocks, so
each time that appears the beginning of each block executes the code
inside "while gets".
The issue is the binary files is 2GB in size and I don't know why the
code works in linux under ruby 2.0 and doesnt work in windows with ruby
2.0.
while gets
line = $_.unpack('H*')[0]
next unless line =~ /Regexp/ #Some code using "line" content
end
##########################################################
Should be something like:
while line = gets(\xff\x45.force_encoding("BINARY"))
FIle.open returns a file object, which you are not saving a reference to
As far as I know gets will default to standard in. does the app wait till
you hit a key?
IO has a binread method that looks applicable
···
On Fri, Sep 13, 2013 at 6:47 PM, Sever Siller <lists@ruby-forum.com> wrote:
Hello Abinoam Jr.,
I've tried adding File.open(ARGV[0], 'rb') too, but is the same error
On Fri, Sep 13, 2013 at 10:06 PM, Chris Hulan <chris.hulan@gmail.com> wrote:
FIle.open returns a file object, which you are not saving a reference to
As far as I know gets will default to standard in. does the app wait till
you hit a key?
irb(main):028:0> File.open('x','rb'){|io| while io.read(1024, buffer);
puts buffer.bytesize; end}
NameError: undefined local variable or method `buffer' for main:Object
from (irb):28:in `block in irb_binding'
from (irb):28:in `open'
from (irb):28
from /usr/bin/irb:12:in `<main>'
Also, there seems to be no point in declaring an encoding when reading binary.
File.open(file, 'rb') do |f|
buffer = ''
while f.read(1024, buffer)
# process the buffer
end
end
Kind regards
robert
···
On Sat, Sep 14, 2013 at 10:20 AM, Tamara Temple <tamouse.lists@gmail.com> wrote:
On Sep 14, 2013, at 12:42 AM, Sever Siller <lists@ruby-forum.com> wrote:
Hello again Chris and Abinoam,
I've tested Chris option but I still receive the error. Maybe is
something of the interpretation or encoding that ruby is not
understanding.
script.rb:18:in `gets': encoding mismatch: CP850 IO with UTF-8 RS
(ArgumentError)
from script.rb:18:in `gets'
from script.rb:18:in `<main>'
I've tested Abinoam option too and I receive this error:
script.rb:50: syntax error, unexpected end-of-input, expecting
keyword_end
Line 50 contains "end". Is the end of the "while gets" loop.
Thanks in advance for your help.
Difficult to know what is happening here.
Wondering if you should specify:
File.open(file, 'rb', :encoding => Encoding::UTF_8 ) do |f|
while (f.read(1024,buffer))
# process the buffer
end
end
while gets
line = $_.unpack('H*')[0]
next unless line =~ /Regexp/ #Some code using "line" content
end
##########################################################
Should be something like:
while line = gets(\xff\x45.force_encoding("BINARY"))