force file write in dos format

M

Martin DeMello

Is there any built-in way to force File.puts to use dos line endings,
regardless of the platform under which the program is running?

martin
 
X

Xavier Noria

Is there any built-in way to force File.puts to use dos line endings,
regardless of the platform under which the program is running?

If I undertand correctly what you want your program is going to
explicitly output pairs "\r\n".

If that's the case, in addition to the recommendation about IO#print
already given take into account that the io needs binmode. Otherwise,
on CRLF platforms you'd end up with "\r\r\n" on disk, which would be
wrong. That's because the single "\n" in "\r\n" gives itself a pair
"\r\n" in text mode. So IO#print CRLF in binmode is the complete
portable solution.

-- fxn
 
M

Martin DeMello

If I undertand correctly what you want your program is going to
explicitly output pairs "\r\n".

If that's the case, in addition to the recommendation about IO#print
already given take into account that the io needs binmode. Otherwise,
on CRLF platforms you'd end up with "\r\r\n" on disk, which would be
wrong. That's because the single "\n" in "\r\n" gives itself a pair
"\r\n" in text mode. So IO#print CRLF in binmode is the complete
portable solution.

Good point. As of now this will only ever be run on a linux box, but
it certainly doesn't hurt to future-proof it.

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top