# Windows CMD and international chars (Ã¥Ã¤Ã¶)

**URL:** <https://www.ruby-forum.com/t/windows-cmd-and-international-chars-a-a-a/165943>\
**Category:** Ruby\
**Created:** [April 20, 2009, 8:13am UTC](https://www.ruby-forum.com/t/windows-cmd-and-international-chars-a-a-a/165943 "2009-04-20T08:13:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![apostoloandre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@apostoloandre](https://www.ruby-forum.com/u/apostoloandre)\
**Post date:** [April 20, 2009, 8:13am UTC](https://www.ruby-forum.com/t/windows-cmd-and-international-chars-a-a-a/165943/1 "2009-04-20T08:13:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apostoloandre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@apostoloandre](https://www.ruby-forum.com/u/apostoloandre)\
**Post date:** [April 20, 2009, 9:30am UTC](https://www.ruby-forum.com/t/windows-cmd-and-international-chars-a-a-a/165943/2 "2009-04-20T09:30:30Z")

</div>

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 ‘ÐŸÑ€ÐµÐ²ÐµÐ´!’

---

<div class="post-metadata">

**Author:** ![apostoloandre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@apostoloandre](https://www.ruby-forum.com/u/apostoloandre)\
**Post date:** [April 20, 2009, 9:47am UTC](https://www.ruby-forum.com/t/windows-cmd-and-international-chars-a-a-a/165943/3 "2009-04-20T09:47:21Z")

</div>

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 ‘ÐŸÑ€ÐµÐ²ÐµÐ´!ÐµÐ´!Ð´!!’

---

<div class="post-metadata">

**Author:** ![apostoloandre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@apostoloandre](https://www.ruby-forum.com/u/apostoloandre)\
**Post date:** [April 20, 2009, 10:06am UTC](https://www.ruby-forum.com/t/windows-cmd-and-international-chars-a-a-a/165943/4 "2009-04-20T10:06:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![apostoloandre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@apostoloandre](https://www.ruby-forum.com/u/apostoloandre)\
**Post date:** [April 20, 2009, 10:31am UTC](https://www.ruby-forum.com/t/windows-cmd-and-international-chars-a-a-a/165943/5 "2009-04-20T10:31:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apostoloandre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/94ad74/32.png) [@apostoloandre](https://www.ruby-forum.com/u/apostoloandre)\
**Post date:** [April 24, 2011, 8:20pm UTC](https://www.ruby-forum.com/t/windows-cmd-and-international-chars-a-a-a/165943/6 "2011-04-24T20:20:47Z")

</div>

```auto
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

```

This solution works. The text is now correctly displayed in Windows  
console.

But my code crashes whenever Ruby faces a string that contains a  
non-CP866 character (like em dash “—”):

in `write’: U+2014 from UTF-8 to IBM866  
(Encoding::UndefinedConversionError)

How do i overcome this error? Not using UTF-8 is not an option.

Iconv has a nice solution: add “//IGNORE” to encoding name and error no  
longer takes place. But IO does not recognize “//IGNORE”, so this  
solution i unacceptable.

I can’t use Iconv instead of IO due to the following reason. I use  
RubyMine. Unlike Windows console, RubyMine console works in pure UTF-8.  
But whenever code run by RubyMine writes to disk, it seems to use  
Windows encoding because text gets written in corrupt encoding. ☹ And i  
do not know a way to distinguish RubyMine from Windows console so that  
my program could perfrom only the conversions necessary for the current  
environment.
