Issues with pack/write on WinXP compared to Linux

Discussion in 'Ruby' started by james.d.masters@gmail.com, Mar 23, 2007.

  1. Guest

    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...
     
    , Mar 23, 2007
    #1
    1. Advertising

  2. Tim Hunter Guest

    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/.
     
    Tim Hunter, Mar 23, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 23, 11:56 am, Tim Hunter <> 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!
     
    , Mar 23, 2007
    #3
  4. Guest

    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
     
    , Mar 23, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    418
    JEDIDIAH
    Jun 20, 2006
  2. Tim Jones
    Replies:
    0
    Views:
    405
    Tim Jones
    Jan 31, 2004
  3. Michele Simionato

    issues installing readine-1.12 on WinXP

    Michele Simionato, Mar 13, 2005, in forum: Python
    Replies:
    6
    Views:
    620
    Michele Simionato
    Mar 14, 2005
  4. Larry
    Replies:
    2
    Views:
    177
    Yan-Hong Huang[MSFT]
    Jul 30, 2003
  5. Alexander Farber

    pack 'C3U*' not same as pack 'C3(xC)*'

    Alexander Farber, Jun 23, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    170
    Ilmari Karonen
    Jun 23, 2005
Loading...

Share This Page