[erlang-questions] io module encoding

José Valim jose.valim@REDACTED
Thu Jun 26 11:51:26 CEST 2014


I have reported two bugs related to this area as I was expecting this
behaviour to change on 17.0:


Only the erlang shell, the one started via the erl command, respects
LC_CTYPE and the +fnu flags. If you pass -noshell, use the "dumb terminal"
(triggered when you set TERM to something else), use stderr, or an escript,
the encoding will remain as latin1.

You can change the encoding in those situations by calling:

io:setopts(standard_io, [{encoding,utf8}]);

I hope this helps,

PS: In case you want to call the line above in your application callback,
you may notice a slow down when starting the application along side the
shell with something like: erl -s my_app start. That's because the
group_leader sends a message to the shell to change the encoding but the
shell is not yet ready. I was able to work around this particular scenario
by using:

case init:get_argument(noshell) of
  {ok, _} -> io:setopts(standard_io, [{encoding,utf8}]);
  error   -> ok

A patch was sent to OTP to fix this particular issue:

*José Valim*
Skype: jv.ptec
Founder and Lead Developer

On Thu, Jun 26, 2014 at 11:28 AM, Camille Troillard <lists@REDACTED> wrote:

> Hello,
> On Mac OS X, when I start an Erlang shell from the command-line the io
> module encoding is set to unicode:
> > Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:8:8]
> [async-threads:10] [hipe] [kernel-poll:false]
> >
> > Eshell V5.10.4  (abort with ^G)
> > 1> os:getenv("LC_CTYPE").
> > "UTF-8"
> > 2> lists:keyfind(encoding, 1, io:getopts()).
> > {encoding,unicode}
> So that’s great.
> Now, I have a GUI application that launches the Erlang shell. At first I
> thought the LC_CTYPE environment variable was not set (which was the case),
> but even when set to UTF-8, this does not work as expected:
> Here's the output of the shell launched by the GUI application:
> > 1> os:getenv("LC_CTYPE").
> > "UTF-8"
> > 2> lists:keyfind(encoding, 1, io:getopts()).
> > {encoding,latin1}
> I want {encoding, unicode}, and don’t understand why it defaults to latin1.
> How can it be?
> The documentation of io says:
> (http://erlang.org/doc/man/io.html)
> > The standard shell will be set for either Unicode or latin1 encoding
> when the system is started. The actual encoding is set with the help of the
> LANG or LC_CTYPE environment variables on Unix-like system or by other
> means on other systems.
> Does Mac OS X applies to “other systems”? If so, what are the “other
> means”?
> Thanks!
> Best,
> Cam
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140626/54eefb0e/attachment.htm>

More information about the erlang-questions mailing list