# How to emit UTF-8 from console mode program?

**URL:** <https://www.ruby-forum.com/t/how-to-emit-utf-8-from-console-mode-program/149920>\
**Category:** Ruby\
**Created:** [October 1, 2008, 7:04am UTC](https://www.ruby-forum.com/t/how-to-emit-utf-8-from-console-mode-program/149920 "2008-10-01T07:04:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siegfried\_Heintze](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Siegfried\_Heintze](https://www.ruby-forum.com/u/Siegfried_Heintze)\
**Post date:** [October 1, 2008, 7:04am UTC](https://www.ruby-forum.com/t/how-to-emit-utf-8-from-console-mode-program/149920/1 "2008-10-01T07:04:23Z")

</div>

The following perl program works when I run it from urxvt-X console on  
cygwin-x windows when running on Microsoft Windows XP:

LC\_CTYPE=en\_US.UTF-8 urxvt-X.exe&  
perl -wle “binmode STDOUT, q[:utf8]; print chr() for 0x410 … 0x430;”

This little one liner prints the Russian alphabet in Cryllic. With some  
slight modification it will also print a lot of other alphabets too –  
including Hebrew, chinese and japanese.

It does not work with cmd.exe because apparently cmd.exe cannot deal  
with  
UTF-8.

Can someone help me translate it into ruby? I would not expect it to  
work  
from cmd.exe with ruby, but I am hopeful it will work with urxvt-X!

Thanks,  
Siegfried

---

<div class="post-metadata">

**Author:** ![Siegfried\_Heintze](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Siegfried\_Heintze](https://www.ruby-forum.com/u/Siegfried_Heintze)\
**Post date:** [October 1, 2008, 8:11am UTC](https://www.ruby-forum.com/t/how-to-emit-utf-8-from-console-mode-program/149920/2 "2008-10-01T08:11:05Z")

</div>

Siegfried Heintze wrote:

> It does not work with cmd.exe because apparently cmd.exe cannot deal with

Quick and dirty (works in Linux xterm -u, ruby 1.8.7):

ruby -Ku -e “(0x410…0x430).each {|x| puts [x].pack(‘U’)}”

The -K option is ‘u’ for setting the encoding to unicode, same as  
setting ‘$KCODE=“u”’ at the beginning of the code.

Array#pack is used because for Integer.chr, 1040ff are out of range.

Hope this helps,

t.
