I have use erlang 21 version. When call "erl", it will run user's .erlang file for loading library's ebin file.
When running the following script by escript, it will not call.
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -sname factorial -mnesia debug verbose
main([String]) ->
try
% io:format("~p",[lager_app:module_info()]),
io:format("aaaa"),
N = list_to_integer(String),
F = fac(N),
io:format("factorial ~w = ~w\n", [N,F])
catch
_:_ ->
usage()
end;
main(_) ->
usage().
usage() ->
io:format("aaaa\n~p",[lager_app:module_info()]),
io:format("usage: factorial integer\n"),
halt(1).
fac(0) -> 1;
fac(N) -> N * fac(N-1).
The error message is as follows:
yuchen@chenyu-Vostro-5468:~/a$ ./factorial
escript: exception error: undefined function lager_app:module_info/0
To resolve the error about ".erlang.cookie must be accessible by owner only" that is mentioned in the title of this post you need to change the cookie permissions to 600. You can use the following command:
chmod 600 ~/.erlang.cookieThe other error message shown in the body of your post about "undefined function lager_app:module_info/0" means that you don't have lager setup properly. If you comment out the line with
lager_appyou should get past that error.Here are the docs on setting up lager. It looks like you will need to configure it in
rebar.configandapp.configand also calllager:start()before using it.I hope this helps.