Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

windows binary mode

2 views
Skip to first unread message

kas...@gmail.com

unread,
Jul 8, 2005, 4:01:00 PM7/8/05
to
Hi, i'm having some trouble with a file in binary mode on winxp.
with this code:

File.open( 'output.out', 'wb+' ) {|fd|
bin_data = [0].pack('c')
fd.putc bin_data
fd.putc "\000"
fd.putc 0x0
fd.putc 0
fd.putc 1
}

have this result

0d0a0d0a0d0a0d0a01

for every 0 write a 0d0a pair... but for 1 write ok.... :(
I write in diferent styles (octal,decimal,hex,pack) but the same
result, I try with syswrite, write, print, printf and the same
problem.... all the numbers write ok, except 0 that write 0d0a .....
there are some flag that I'm missing ? or some magic to do ?

ruby --version
ruby 1.8.2 (2004-12-25) [i386-mswin32]


TIA
:: nelson ::

daz

unread,
Jul 8, 2005, 5:21:32 PM7/8/05
to

nelson wrote:
> Hi, i'm having some trouble with a file in binary mode on winxp.
> with this code:
>
> File.open( 'output.out', 'wb+' ) {|fd|
> bin_data = [0].pack('c')
> fd.putc bin_data
> fd.putc "\000"
> fd.putc 0x0
> fd.putc 0
> fd.putc 1
> }
>
> have this result
>
> 0d0a0d0a0d0a0d0a01
>

It's OK on Windows 98se + ruby 1.8.3 (2005-05-12) [i586-bccwin32]

00000000h: 00 00 00 00 01 ; .....

File.open('output.out', 'rb') {|fd| puts fd.read.dump}

#-> "\000\000\000\000\001"

Your script is OK.
Make sure you are using a reliable viewer to confirm the result.
If there's still a problem, please let us hear.

daz


Ryan Leavengood

unread,
Jul 8, 2005, 5:45:37 PM7/8/05
to
daz said:
>
> It's OK on Windows 98se + ruby 1.8.3 (2005-05-12) [i586-bccwin32]
>
> 00000000h: 00 00 00 00 01 ; .....
>
> File.open('output.out', 'rb') {|fd| puts fd.read.dump}
>
> #-> "\000\000\000\000\001"
>
> Your script is OK.
> Make sure you are using a reliable viewer to confirm the result.
> If there's still a problem, please let us hear.

It is also fine on Windows XPsp2 with ruby 1.8.2 (2004-12-25) [i386-mswin32].

Ryan


kas...@gmail.com

unread,
Jul 11, 2005, 12:16:47 PM7/11/05
to
hi,
I allways use PsPad in Hexview to test the result, and never try other
viewer.... sorry.. you are right... all is ok with ruby.....I try
reading with ruby and with another hexviewer and all is ok.... (will
report the bug to pspad people)

sorry for the noise....

:: nelson ::

0 new messages