[erlang-questions] Where does io:format's output go? Or where SHOULD it go?

Raimo Niskanen <>
Fri Apr 25 09:49:05 CEST 2008


On Thu, Apr 24, 2008 at 08:37:37PM -0700, Deryk Barker wrote:
> Excuse me if this is a dim question; although I am a fan of Erlang, my 
> experience is limited: I teach at a college and this will be only the 
> second time I've introduced the language (and the FP paradigm) into our 
> Network Programming course.
> 
> While setting up a demo for my students to show them how simple it is to 
> load code into another Erlang node and to start processes in another 
> node, when I do this - I start a shell on two systems in two windows, 
> load code from one node to the other and start it - it doesn't matter 
> whether I start the process on the second node via spawn/4 or 
> rpc:call/4, the output, written via io:format by the process on the 
> second node always appears on the first node.
> 
> Is this a feature of the shell?

Not really.

Every erlang process has a "group leader", and that is a process that
io:format/2,3 per default use as IO server for output.

Check out erlang:group_leader/0,1.

spawn/4 makes the spawned process inherit the parent's group leader.

rpc:call/4 passes the caller's group leader to the RPC server,
and the RPC server sets the group leader of spawned process that
executes the RPC call.

And since it does not matter much if a process is 
local or remote remote it works just fine with a remote
group leader.

If you instead call erlang:display/1 via RPC you will see
the argument is displayed on the executing node's terminal.

> 
> And a related question: when I run the shell with the -detached flag and 
> start a process via -eval where does the io:format output go then?
> 

The erlang node detaches from its terminal and all io:format
output (that goes to the default group leader (that prints
on STDOUT)) goes to /dev/null.

> -- 
> 
> Deryk Barker, Computer Science Dept.        Music does not have to be 
> understood
> Camosun College, Victoria, BC, Canada        It has to be listened to.
> email: 
> phone: +1 250 370 4452                                      Hermann 
> Scherchen.
> 
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list