Comparing
version 3 and
version 2 backh1. Random Erlang Pieces of Code
h2. Add directory to the binaries search path
Add these lines to your _~/.erlang_
code:add_path("/ebin").
code:add_path("/ebin").
h2. Spawn process on another node
remote$ % cat dummy.erl
-module(dummy).
-export([loop/0]).
loop() ->
receive
{Node, Msg} ->
io:format("~s : ~s~n", [Node, Msg]),
loop();
_ -> io:format('not defined~n')
end.
remote$ erl -sdummy
dummy@remote> c(dummy).
local$ erl -sname hello
hello@local> Node = 'dummy@remote'.
hello@local> net_adm:ping(Node).
%% Format: Pid = spawn(Node, mod_name, func_name, [arg1,arg2]).
hello@local> Pid = spawn(Node, dummy, loop, []).
hello@local> Pid ! {self(), 'Hello'}.
h2. Convert command line argument to integer
-module(dummy).
-export([main/1]).
main([Arg|_]) ->
Val = list_to_integer(atom_to_list(Arg)),
...
host$ erl -noshell -s dummy main 1000 -s init stop