[erlang-questions] io:getopts() possibly unset when evaluating code

José Valim <>
Tue Apr 3 12:02:59 CEST 2012

It seems that, when evaluating code via -eval (or -s or -run), the standard
IO options are not yet set.
In my case, what happens is that the encoding is still set to latin1, while
it should be unicode.

Here is how I reproduce the issue:

$ erl -eval 'io:format("~p~n", [io:getopts()]), halt().'


However, invoking io:getopts() inside the shell returns the proper result:

Eshell V5.9  (abort with ^G)
1> io:getopts().

This means that, if I print any unicode value during -eval (or -s or -run),
it will fail by printing question marks instead of the accented words. This
can be verified with:

$ erl -eval 'io:put_chars(<<"josé"/utf8>>), halt().'

The same inside the console prints correctly.

Is this a bug?
Regardless if it is a bug or not, should I just set
io:setopts([{encoding,unicode}]) for now?


José Valim
Founder and Lead Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120403/1ae8db43/attachment.html>

More information about the erlang-questions mailing list