[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Char conversion when using puts to write file lint by line

Gabriel Miró

4/24/2009 5:06:00 PM

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
--
Posted via http://www.ruby-....