Char conversion when using puts to write file lint by line

G

Gabriel Miró

I'm trying to create a script to generate several win32 registry entries
in a .reg file, using a template. The idea is that I have a registry
entry in the template file with tokens to be replaced by values I
determine.
I'm getting a weir behavior when trying to do the following:

def createFromTemplate (src, template,filename)
raise "Template file not found "+template if !File.file?(template)
f = File.open(template)
nf = File.new(filename,'w+')
f.each{|line|
nf.write line
}
end

I would expect this code to copy all the lines from the template file to
the result file. Instead I'm getting the following:

Template file:
Windows Registry Editor Version 5.00

[HKEY_USERS\S-1-5-21-216280869-1618010840-3877511435-1006\Software\SimonTatham\PuTTY\Sessions]

[HKEY_USERS\S-1-5-21-216280869-1618010840-3877511435-1006\Software\SimonTatham\PuTTY\Sessions\PORTAL001%20CMPT%201%20-%20DB%20Tunnels]
"Present"=dword:00000001
"HostName"="172.18.142.94"
...

Result file:
Windows Registry Editor Version 5.00
à¨à´€à´€
[HKEY_USERS\S-1-5-21-216280869-1618010840-3877511435-1006\Software\SimonTatham\PuTTY\Sessions]
à¨à´€à´€
[HKEY_USERS\S-1-5-21-216280869-1618010840-3877511435-1006\Software\SimonTatham\PuTTY\Sessions\PORTAL001%20CMPT%201%20-%20DB%20Tunnels]
à¨âˆ€å€€çˆ€æ”€çŒ€æ”€æ¸€ç€âˆ€ã´€æ€çœ€æ¼€çˆ€æ€ã¨€ã€€ã€€ã€€ã€€ã€€ã€€ã€€ã„€à´€à´€
"HostName"="172.18.142.94"
...

Notice that the fn.puts call is adding unrecognized characters where in
the template file I would find CRLF.
If I do a File.copy, the file gets copyied without any char conversion.
Can someone help me determine what might be happening? I'm clueless.

I'm running Ruby 1.9 on Windows XP.

Regards
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top