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
Post a Comment