I have an Erlang application named tb that runs fine from Erlang command line by doing application:start(tb). Whereas when I try to invoke the same application from inside escript using os:cmd, the application doesn't seem to run. When i do a 'ps | grep beam', I see the beam.smp process running. But the application is not generating any output.What might be the problem? Is there a better way to start another erlang VM from inside escript?
Here's the code snippet:
net_kernel:start([tb_escript, shortnames]),
read_config_file(FName),
Cookie = get(cookie),
Node = get(node),
N = io_lib:format("~p",[Node]),
lists:flatten(N),
C = io_lib:format("~p",[Cookie]),
lists:flatten(C),
EBIN = "~/tb/ebin",
erlang:set_cookie(tb_escript,Cookie),
os:cmd("erl -pa " ++ EBIN ++ " -sname " ++ N ++ " -detached " ++ " -setcookie " ++ C ++ " -s application start tb").
This happens because the args flag to
-swraps the arguments in a list and passes that tomodule:function/1.-s application start tbwill executeapplication:start([tb]), which would return{error,{bad_application,[ssl]}}. As this is just a normal return value, no error is printed byerl.From the
erldocumentation:There are two ways to solve this:
Use
-eval "application:start(tb)", as you already mentioned in a comment.Add a
start/0(if not already present) function totbwhich callsapplication:start(tb), and then pass just-s tbtoerl.-swith a single argument will callmodule:start().