Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Issues with pack/write on WinXP compared to Linux

Reply
Thread Tools

Issues with pack/write on WinXP compared to Linux

 
 
james.d.masters@gmail.com
Guest
Posts: n/a
 
      03-23-2007
I'm sure that this has to do with CR/LF on DOS/Windows filesystems,
but I'm not sure how to fix:

File.open('test', 'w') do |file|
file.write([10].pack('n')) #=> 2 [bytes]
end

On Linux, the file comes out as having 2 bytes (as expected):

% ls -l test
-rw-rw-r-- 1 jamesm eng 2 Mar 23 11:38 test
% od -h test
0000000 0a00
0000002

On WinXP it has 3 bytes (BTW, write still returns 2 [bytes] in irb on
WinXP):

bash-2.05a$ ls -l test
-rw-r--r-- 1 Administ None 3 Mar 23 11:40 test
bash-2.05a$ od -h test
0000000 0d00 000a
0000003

This does not happen when writing out another number (say 11). Again,
it's probably a CR/LF deal, but I don't know how to remedy. Thanks in
advance...

 
Reply With Quote
 
 
 
 
Tim Hunter
Guest
Posts: n/a
 
      03-23-2007
unknown wrote:
> I'm sure that this has to do with CR/LF on DOS/Windows filesystems,
> but I'm not sure how to fix:
>
> File.open('test', 'w') do |file|
> file.write([10].pack('n')) #=> 2 [bytes]
> end


File.open('test', 'wb') do |file|

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
james.d.masters@gmail.com
Guest
Posts: n/a
 
      03-23-2007
On Mar 23, 11:56 am, Tim Hunter <rmag...@gmail.com> wrote:
> File.open('test', 'wb') do |file|


Excellent - I knew it was something simple. This was my first binary
and DOS/Windows project in Ruby... Thanks!

 
Reply With Quote
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      03-23-2007
On Sat, 24 Mar 2007 wrote:

> I'm sure that this has to do with CR/LF on DOS/Windows filesystems,
> but I'm not sure how to fix:
>
> File.open('test', 'w') do |file|

^
^
^
wb

-a
--
be kind whenever possible... it is always possible.
- the dalai lama

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Why Linux and Windows NT series are not fairly compared roy.schestowitz@yahoo.com Java 5 06-20-2006 01:15 PM
Re: Desktop slower in linux compared to windows Vincent Burks Computer Support 2 12-02-2005 04:47 PM
Re: Desktop slower in linux compared to windows Glass slopper Computer Support 0 12-01-2005 07:06 PM
Re: OsX compared to Linux and BeOS Ruel Smith Digital Photography 2 02-13-2005 03:18 PM
Linux and Windows Security Compared. TechNews Computer Support 3 06-11-2004 11:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57