From: Heesob Park Date: 2011-12-15T19:32:18+09:00 Subject: Re: Encoding woes with command promt output --20cf307f386c8a118b04b41effe9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, 2011/12/15 Chris Lervag > Im working on a script which is going to be printing some non-ascii > characters (=C3=A6=C3=B8=C3=A5), and for the life of me, I just cant seem= to make it > print in the Windows Command Prompt terminal! I think I have done what > should be enough to make it work, defining the encoding in my ruby file, > but it just isnt working. However, if I try to print the same > characters in irb, it works just fine. I can make it work by injecting > hex values in my strings, but Id rather not have to do that, as that > code isnt very readable. Im at a loss here, and would be grateful if > anyone can help me out with my encoding woes! > > OS: Windows XP 32 bit SP3 > > C:\>ruby -v > ruby 1.9.2p180 (2011-02-18) [i386-mingw32] > > Content in file test.rb: > # Encoding: CP850 > puts "=C3=A6=C3=B8=C3=A5" > puts "\x91\x9B\x86" > puts Encoding.default_external > > It seems that the actual encoding of test.rb is not CP850 but UTF-8. The string "=C3=A6=C3=B8=C3=A5" is encoded as "\xC3\xA6\xC3\xB8\xC3\xA5" in= UTF-8. > C:\>ruby test.rb > =E2=94=9C=C2=AA=E2=94=9C=C2=A9=E2=94=9C=C3=91 > =C3=A6=C3=B8=C3=A5 > CP850 > > The string "=E2=94=9C=C2=AA=E2=94=9C=C2=A9=E2=94=9C=C3=91" is "\xC3\xA6\xC3= \xB8\xC3\xA5" in CP850. > C:\>irb > irb(main):001:0> puts "=C3=A6=C3=B8=C3=A5" > =C3=A6=C3=B8=C3=A5 > =3D> nil > irb(main):002:0> puts "\x91\x9B\x86" > =C3=A6=C3=B8=C3=A5 > =3D> nil > irb(main):003:0> puts Encoding.default_external > CP850 > > > Regards, > Chris > > Regards, Park Heesob --20cf307f386c8a118b04b41effe9--