<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Trying to track down the difference between -noinput and lack
thereof, I find this:<br>
<blockquote>$ erl -eval 'io:format("~p / ~p\n",
[process_info(whereis(user), A) || A <- [initial_call,
current_function]]), init:stop().' <br>
Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:8:8] [rq:8]
[async-threads:0] [kernel-poll:false]<br>
<br>
Eshell V5.8.4 (abort with ^G)<br>
1> {initial_call,{group,server,3}} /
{current_function,{group,server_loop,3}}<br>
<br>
<br>
$ erl -eval 'io:format("~p / ~p\n", [process_info(whereis(user),
A) || A <- [initial_call, current_function]]), init:stop().'
-noinput<br>
{initial_call,{erlang,apply,2}} /
{current_function,{user,server_loop,2}}<br>
</blockquote>
I.e. in one case, 'group' is handling I/O, while in the other, it is
'user'.<br>
In fact, in both cases, only one of the modules is loaded at all:<br>
<blockquote>$ erl -eval 'io:format("~p\n", [{code:is_loaded(user),
code:is_loaded(group)}]), init:stop().' <br>
Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:8:8] [rq:8]
[async-threads:0] [kernel-poll:false]<br>
Eshell V5.8.4 (abort with ^G)<br>
1>
{false,{file,"/usr/local/lib/erlang/lib/kernel-2.14.4/ebin/group.beam"}}<br>
<br>
$ erl -eval 'io:format("~p\n", [{code:is_loaded(user),
code:is_loaded(group)}]), init:stop().' -noinput<br>
{{file,"/usr/local/lib/erlang/lib/kernel-2.14.4/ebin/user.beam"},false}<br>
</blockquote>
The differences in behaviour are caused by differences between these
two modules.<br>
The character encoding translation is done in group:io_request/3 and
user:wrap_characters_to_binary/3, respectively (it is the latter
which produces the "\x" escapes).<br>
<br>
/Erik<br>
<br>
On 22-11-2011 11:02, Erik Søe Sørensen wrote:
<blockquote cite="mid:4ECB7322.8080505@trifork.com" type="cite">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
I thought it might have something to do with io:setopts() being
called when -noinput is absent, and not when it is present; the
evidence is mixed, but I think I may be on to something useful.<br>
<br>
Consider the following extension of your program:<br>
<blockquote>-module(unicode_test).<br>
-export([main/0]).<br>
<br>
main() -><br>
print(),<br>
ok = io:setopts(standard_io, [{encoding, unicode}]),<br>
print().<br>
<br>
print() -><br>
io:format("Encoding=~p~n",
[lists:keyfind(encoding,1,io:getopts())]),<br>
io:format("~ts~n",
[[1058,1077,1089,1090,1086,1074,1072,1103,32,1089,1090,1088,1086,1082,1072]]),<br>
io:format("~ts~n", ["Тестовая строка"]).<br>
</blockquote>
<br>
Without -noinput (and with LANG=da_DK.utf8), I get:<br>
<blockquote>1> Encoding={encoding,latin1}<br>
Тестовая строка<br>
ТеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока<br>
Encoding={encoding,latin1}<br>
Тестовая строка<br>
ТеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока<br>
</blockquote>
i.e. the list-of-integers version is OK in both cases.<br>
<br>
With -noinput, I get:<br>
<blockquote>Encoding={encoding,latin1}<br>
\x{422}\x{435}\x{441}\x{442}\x{43E}\x{432}\x{430}\x{44F}
\x{441}\x{442}\x{440}\x{43E}\x{43A}\x{430}<br>
Тестовая строка<br>
Encoding={encoding,unicode}<br>
Тестовая строка<br>
ТеÑÑÐ¾Ð²Ð°Ñ ÑÑÑока<br>
</blockquote>
I.e. first the string-literal version is good, but after using
io:setopts(), the list-of-integers version is the good one.<br>
<br>
So, if you explicitly select unicode encoding in your program, you
have consistent behaviour.<br>
<br>
The only thing that bothers me is that there appears to be
something else going on - it's not just about the encoding.<br>
I find that without -noinput, output is consistent no matter what
I set encoding to. With -noinput, on the other hand, output
differs whether I select latin1 or unicode encoding.<br>
<br>
Hoping this helps.<br>
/Erik<br>
</blockquote>
<br>
</body>
</html>