[erlang-questions] Question re console io in a distributed computation
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? "])
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.)
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
> 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
> Thank you,
>> 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
>>>> 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
>>> Ulf W
> erlang-questions mailing list
More information about the erlang-questions