# Issues with pack/write on WinXP compared to Linux

**URL:** <https://www.ruby-forum.com/t/issues-with-pack-write-on-winxp-compared-to-linux/89920>\
**Category:** Ruby\
**Created:** [March 23, 2007, 7:51pm UTC](https://www.ruby-forum.com/t/issues-with-pack-write-on-winxp-compared-to-linux/89920 "2007-03-23T19:51:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 23, 2007, 7:51pm UTC](https://www.ruby-forum.com/t/issues-with-pack-write-on-winxp-compared-to-linux/89920/1 "2007-03-23T19:51:06Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 23, 2007, 7:56pm UTC](https://www.ruby-forum.com/t/issues-with-pack-write-on-winxp-compared-to-linux/89920/2 "2007-03-23T19:56:28Z")

</div>

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|

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 23, 2007, 8:11pm UTC](https://www.ruby-forum.com/t/issues-with-pack-write-on-winxp-compared-to-linux/89920/3 "2007-03-23T20:11:09Z")

</div>

On Mar 23, 11:56 am, Tim H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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!

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 23, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/issues-with-pack-write-on-winxp-compared-to-linux/89920/4 "2007-03-23T22:32:23Z")

</div>

On Sat, 24 Mar 2007 removed\_email\_address@domain.invalid 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
