windows cmd, ruby irb and utf-8
steps for viewing utf-8 chars in irb on windows:
A. set the console to use a TrueType font
B. set the console to use CP_UTF8 (set chcp 65001)
C. start irb via explicit path in ruby: ruby C:\Ruby\bin\irb
A1. open a cmd.exe, right click top of window -> properties (set to a TrueType font ;
I only have Lucida Console and Raster Fonts, so set to Lucida Console)
B1. C:\Documents and Settings\Administrator>chcp 65001
C1. C:\Documents and Settings\Administrator>Ruby C:\Ruby\bin\irb
2 example sessions
==========================
Session with non working utf8.
==========================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>
C:\Documents and Settings\Administrator>chcp
Active code page: 437
C:\Documents and Settings\Administrator>irb
irb(main):001:0> puts "\303\253"
ë
=> nil
irb(main):002:0>
after doing the above (ABC) steps:
==========================
Session with 'working' utf8. (sort of)
==========================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>
C:\Documents and Settings\Administrator>chcp 65001
Active code page: 65001
C:\Documents and Settings\Administrator>Ruby C:\Ruby\bin\irb
irb(main):001:0> puts "\303\253"
ëErrno::EACCES: Permission denied
from (irb):2:in `write'
from (irb):2:in `puts'
from (irb):2
irb(main):003:0> puts "\303\253\n"
ë
=> nil
(not sure what what the permission denied is all about but adding a newline removes the warning)
ok, now lets try for the utf-8 test, print the string: Iñtërnâtiônàlizætiøn
irb(main):017:0> s = 'I' << [195,177].pack('cc') << 't' << "\303\253" << 'rn' << [195,162].pack('cc') << 'ti' << [195,180].pack('cc') << 'n' << [195,160].pack('cc') << 'liz' << [195,166].pack('cc') << 'ti' << [195, 184].pack('cc') << 'n' => "I\303\261t\303\253rn\303\242ti\303\264n\303\240liz\303\246ti\303\270n"
irb(main):018:0> puts s+"\n"
Iñtërnâtiônàlizætiøn
tiøn
n
=> nil
irb(main):019:0> puts s+"\n"
Iñtërnâtiônàlizætiøn
tiøn
n
=> nil
irb(main):020:0> puts s
Iñtërnâtiônàlizætiønætiønnn
=> nil
irb(main):023:0> puts "I\303\261t\303\253rn\303\242ti\303\264n\303\240liz\303\246ti\303\270n"
Iñtërnâtiônàlizætiønætiønnn
=> nil
(ok, so it almost works,... - not sure what the extra 'n's and tiøn are all about)
references:
http://www.ruby-forum.com/topic/87447
http://blogs.msdn.com/michkap/archive/2006/03/06/544251.aspx
http://intertwingly.net/stories/2004/04/14/i18n.html
addendum:
If you are running Watir tests from the command line and want to be able to input strings into html form elments, such as str = 'Iñtërnâtiônàlizætiøn'.
do A1 and B1 above
