How to write DOS line endings to a file from Unix
There's an option for this, the same one you're using on encode
also works with File.open
:
File.open('/tmp/foo', mode: 'w', crlf_newline: true) do |file| file.puts("alpha") file.puts("beta")end
This option not only ends lines in \r\n
, it also translates any explicit \n
into \r\n
. So this:
file.puts("alpha\nbar")
will write alpha\r\nbar\r\b