[erlang-questions] Question re console io in a distributed computation

Ulf Wiger <>
Wed Oct 29 21:01:50 CET 2008


Well, I'm not quite sure why it didn't work with the group leader
(I'd have to dig into that), but the 'user' trick ought to work with
the question as well. Compare:

rpc:call(OtherNode, io, get_line, ["Hello? "])

with

rpc:call(OtherNode, io, get_line, [user, "Hello? "]).

The first version should give a prompt on the originating node,
and the second version should give it on the target node
(assuming, of course, that the target node has a shell.)

BR,
Ulf W

2008/10/29 David Cabana <>:
> I've now played with both of  Ulf's suggested approaches  (using
> io:format(user, Fmt, Args), or alternatively, resetting processes group
> leaders) and have gotten output to go the correct consoles with both
> approaches.  Which of course led to the next hurdle,  reading input from the
> player console.
>
> The referee sent a question to the player, which was written to the player
> node's console. What I want to do is type a response in the player console,
> have it read, parsed, and sent to the referee, but so far no luck. My
> responses vanish into the ether, and the referee hangs waiting for players
> to respond.
>
> Here is how I am trying to respond. When the player process receives a
> question, it writes to the console and tries to read a line:
>
> <when I have reset player group leaders>
>     io:fwrite("~n~s", [Question]),
>     Reply = io:get_line(["= "]),
>
> <did not mess with group leaders, instead specified the 'user' atom during
> io>
> I have also tried:
>     io:fwrite(user, "~n~s", [Question]),
>     Reply = io:get_line(user, ["= "]),
>
>
> It occurs to me that maybe I am going about this the wrong way? Perhaps my
> approch is misconceived.  I have to believe that console IO in a
> client-server setting is pretty common. Can anyone point me in the right
> direction?
>
> Thank you,
> David
>>
>> On Fri, Oct 24, 2008 at 2:44 PM, Ulf Wiger (TN/EAB)
>> <> wrote:
>>>
>>> David Cabana skrev:
>>> >
>>>>
>>>> The messages flow correctly, but all the terminal io happens in
>>>> a single console, the one associated with the referee node.
>>>>
>>>> My question is how to get player output written to the console of the
>>>> corresponding
>>>> player node?
>>>
>>> Use io:format(user, Fmt, Args)
>>>
>>> Alternatively, set the group leader of the process to some
>>> local process - e.g. the group leader of net_kernel
>>> (found by calling process_info(whereis(net_kernel),group_leader)).
>>>
>>> The group leader is the process that's handed all io messages.
>>> The rpc server deliberately sets the group leader of an rpc
>>> handler process to that of the caller on the originating node,
>>> since the remote node may not always have a tty to print to.
>>> When spawning, the group leader of the spawned process will
>>> be inherited from the parent. If you spawn a process on
>>> another node, it will still have the same group leader as
>>> the parent.
>>>
>>> The BIF group_leader(Pid,New_group_leader_pid) sets a new
>>> leader.
>>>
>>> BR,
>>> Ulf W
>>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list