Displaying messages in a remote node IO

Per Bergqvist per@REDACTED
Sat Dec 21 09:20:37 CET 2002


You may also use io:format/3 to selectively output to different       
destinations.                                                         
                                                                      
RP = rpc:call(Node1,erlang,list_to_pid,["<0.0.0>"]),                  
io:format(RP,"Hello World !\n",[]).                                   
                                                                      
A side note on use of io:format for remote logging:                   
                                                                      
Using io:format directly for logging is not an ideal solution.        
io:format may cause the calling process to hang if the output file    
handling process disappears.                                          
It is better to have your own protocol for distributing log events to 
a logger server on the remote node that does the actual io.           
                                                                      
/Per                                                                  
                                                                      
> Good day,                                                           
>                                                                     
> As in Unix all IO is sent to group leader process.                  
>                                                                     
> There is a trick I've got from:                                     
>                                                                     
>                                                                     
http://www.erlang.org/ml-archive/erlang-questions/200205/msg00004.html
>                                                                     
> If we on Node2:                                                     
>                                                                     
> RP = rpc:call(Node1,erlang,list_to_pid,["<0.0.0>"]),                
> erlang:group_leader(RP,self()),                                     
> io:format("Hello World !\n").                                       
>                                                                     
> and all output from your process will be redirected to Node1.       
>                                                                     
> Best Regards,                                                       
> Vladimir Sekissov                                                   
>                                                                     
> erlang>                                                             
> erlang> Thank you for all your responses.                           
> erlang>                                                             
> erlang> I have started the code below in Node 1.                    
> erlang> I'd like to send a message from Node 2 to Node 1 and display
it in Node 1                                                          
> erlang> I don't figure out what should I modify in this code to do  
this.                                                                 
> erlang>                                                             
> erlang> %%%%%%%%%%%%%%%%                                            
> erlang>                                                             
> erlang> -module(logger).                                            
> erlang> -export([start/0, stop/0]).                                 
> erlang>                                                             
> erlang>                                                             
> erlang> start() ->                                                  
> erlang>     spawn(fun() -> init() end).                             
> erlang>                                                             
> erlang> stop() ->                                                   
> erlang>     logger ! {stop, self()}.                                
> erlang>                                                             
> erlang> init() ->                                                   
> erlang>     register(logger, self()),                               
> erlang>     process_flag(trap_exit, true),                          
> erlang>     loop().                                                 
> erlang>                                                             
> erlang> loop() ->                                                   
> erlang>     receive                                                 
> erlang>  {call, Caller, Msg} ->                                     
> erlang>       {self(), sender, Msg},                                
> erlang>       io:format('Logger closed ~w ~n', Msg)                 
> erlang>       loop();                                               
> erlang>  {stop, Caller} ->                                          
> erlang>       io:format('Logger closed ~n'),                        
> erlang>      exit(normal)                                           
> erlang>     end.                                                    
> erlang>                                                             
> erlang> %%%%%%%%%%%%                                                
> erlang>                                                             
> erlang> Thanks,                                                     
> erlang> Eduardo Figoli                                              
> erlang> INSwitch Solutions                                          
> erlang>                                                             
> erlang>                                                             
> erlang>                                                             
> erlang>                                                             
>                                                                     
=========================================================             
Per Bergqvist                                                         
Synapse Systems AB                                                    
Phone: +46 709 686 685                                                
Email: per@REDACTED                                                   
                                                                      



More information about the erlang-questions mailing list