[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Windows CMD and international chars (åäö

Andre Arvidsson

4/20/2009 6:13:00 AM

Hi all,

I have been pondering over a problem and I have been trying to find (if
there is any) a solution to it.

I am a Swedish user and I willingly admit that I am a newb with Ruby. I
am trying to create a console based db interface (sqlite) but I am
having problems printing Swedish characters (åäö���). When searching
around and reading up on the problem I seem to run into a dead end
wherever I turn. Solutions concerning this problem when using Rails is
fairly easy to find but so far I have found none when just scripting in
a windows console.

So my question to all you wise Ruby coders out there is this: Is there a
solution to my problem and if so what is it?

Thanks in advance.

/sweRascal
--
Posted via http://www.ruby-....

4 Answers

Andrey Kuznecov

4/20/2009 7:31:00 AM

0

Andre Arvidsson wrote:
> Hi all,

> So my question to all you wise Ruby coders out there is this: Is there a
> solution to my problem and if so what is it?
>

You have to set 'Lucida Console' as console font in window properties.
You may change console code page by 'chcp' command:

C:\XP\system32>chcp
Active code page: 1251

C:\XP\system32>chcp 65001
Active code page: 65001 <------- UTF-8

I use this:

# encoding: utf-8

#Kernel::system('chcp 1251>nul')

Encoding.default_external = Encoding.find(Encoding.locale_charmap)
Encoding.default_internal = __ENCODING__

[STDIN, STDOUT, STDERR].each do |io|
io.set_encoding(Encoding.default_external, Encoding.default_internal)
end

puts
"[#{Encoding.locale_charmap}::#{Encoding.default_external}|#{Encoding.default_internal}]"

puts 'Ð?Ñ?евед!'



--
Posted via http://www.ruby-....

Andrey Kuznecov

4/20/2009 7:47:00 AM

0

Andrey Kuznecov wrote:
> You have to set 'Lucida Console' as console font in window properties.
> You may change console code page by 'chcp' command:
>

> C:\XP\system32>chcp 65001
> Active code page: 65001 <------- UTF-8
>

But I know there is a bug:

C:\XP\system32>ruby -v
C:\users\Administrator\RubymineProjects\TestApp\main.rb
ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-mswin32]

[CP65001::UTF-8|UTF-8]
Ð?Ñ?евед!ед!д!! <------- BUG

It must be 'Ð?Ñ?евед!' not 'Ð?Ñ?евед!ед!д!!'
--
Posted via http://www.ruby-....

Andrey Kuznecov

4/20/2009 8:06:00 AM

0

Andrey Kuznecov wrote:
>> C:\XP\system32>chcp 65001
>> Active code page: 65001 <------- UTF-8

In windows there are two locales: console (DOS VM) and system (OS) but
Ruby makes no difference.
--
Posted via http://www.ruby-....

Andre Arvidsson

4/20/2009 8:31:00 AM

0

Andrey Kuznecov wrote:
> Andrey Kuznecov wrote:
>>> C:\XP\system32>chcp 65001
>>> Active code page: 65001 <------- UTF-8
>
> In windows there are two locales: console (DOS VM) and system (OS) but
> Ruby makes no difference.

Thanks alot!

I did a
system('chcp 1252>nul')

at the start of the file and now åäö��� print correctly....

Again thanks and amazing how quick I got an answer to the question...

/Andre
--
Posted via http://www.ruby-....