[erlang-questions] Autogenerating node names

Zvi exta7@REDACTED
Thu Dec 11 14:42:23 CET 2008


Hi David,

This is the code I using:


start_node(NodeName, Cookie) ->
	_Pid = spawn(os,cmd,[os:find_executable("epmd")++" -daemon"]),
	%% TODO: find something better than sleeep, to wait until epmd is up
	timer:sleep(1000),
	{ok, _} = net_kernel:start([to_atom(NodeName), shortnames]),
	true = erlang:set_cookie(node(), to_atom(Cookie)).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% convert any sensible input argument to atom:
%%	i.e, atom, binary, list string, deeplist / IO-list
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
to_atom(S) when is_atom(S) -> S;
to_atom(S) when is_binary(S) -> list_to_atom(binary_to_list(S));
to_atom(S) when is_list(S) -> 
	try list_to_atom(S) of 
	    Val -> Val
	catch 
	    error : _ ->  list_to_atom(binary_to_list(erlang:iolist_to_binary(S)))
	end.


-- 
View this message in context: http://www.nabble.com/Autogenerating-node-names-tp20955536p20955645.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list