Mingw Replaces \r with \n

19 views
Skip to first unread message

aj.palkovic

unread,
May 9, 2011, 2:21:41 PM5/9/11
to RubyInstaller
This line of code demonstrates the problem:
File.open('test', 'w'){|f| f.write "a\rb"}; File.read('test')

This should produce "a\rb". That is what MRI 1.9.2 on Ubuntu produces
as well.
However, Mingw produces: "a\nb"

ruby -v:
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

Is this the expected behavior? It seems weird, especially because
ruby on linux does not change the data.

Luis Lavena

unread,
May 9, 2011, 2:25:23 PM5/9/11
to rubyin...@googlegroups.com

This is not "MinGW" but how files works on Windows.

On Windows files can be open as text-mode and binary-mode. Text-mode
is the default for Ruby.

On Linux/OSX, binary-mode is the only mode available.

If you want your file line-endings not be transformed by Ruby
automatically, open the file in binary mode:

File.open("test", "wb") { |f| f.write "a\rb" }

Sometimes I wish Ruby completely ignored Windows text-mode files and
used binary by default...

--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

AJ Palkovic

unread,
May 9, 2011, 2:27:00 PM5/9/11
to rubyin...@googlegroups.com
Cool.  I figured it was something weird like that, but I couldn't find much.

Thanks.


--
You received this message because you are subscribed to the Google Groups "RubyInstaller" group.
To post to this group, send email to rubyin...@googlegroups.com.
To unsubscribe from this group, send email to rubyinstalle...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyinstaller?hl=en.


Reply all
Reply to author
Forward
0 new messages