How to preserve line endings in Ruby on Windows? -


i running ruby 1.9.3 on windows. when run following snippet of code

text = file.read(path) file.write(path, text) 

i exact same file when file has cr+lf line endings. when run on file lf line endings, changes cr+lf line endings.

how can read , write file using ruby on windows such line endings preserved, whether cr+lf or lf?

ruby, along perl , python, aware of os code running on, , automatically set line-endings should be.

if read, write, text file, settings kick in, , you'll see file change are.

if need have file unchanged, add b flag open statement, like:

file.open('path', 'wb') |fo|   fo.write(text) end 

for more information, see "io open mode".


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -