问题
I have a simple Erlang command that I want to invoke via erl -eval
(to compile erlydtl template, as described on erlydtl page).
When I do it interactively from shell everything works fine and the command exits immediately:
erl -pa ebin deps\erlydtl\ebin Eshell V5.9.3.1 (abort with ^G)
1> erlydtl:compile('templates/tictactoe.dtl',tictactoe_dtl,[{out_dir,'ebin'}]).
ok
But when I try to do it via erl -eval
(I want to run this from .bat file):
erl -pa ebin deps\erlydtl\ebin -noshell -eval erlydtl:compile('templates/tictactoe.dtl',tictactoe_dtl,[{out_dir,'ebin'}])
Then the command does its job (template is compiled) but it doesn't exit and I need to kill the shell process manually with ctrl+c (I'm working under Windows).
I just want the command to compile the template and exit. What may be the problem?
Update:
One solution may be appending exit() invocation at the end of command, but then I end up with following:
erl -pa ebin deps\erlydtl\ebin -noshell -eval erlydtl:compile('templates/tictactoe.dtl',tictactoe_dtl,[{out_dir,'ebin'}]),exit(success).
{"init terminating in do_boot",success}
Crash dump was written to: erl_crash.dump
init terminating in do_boot (success)
The error message is very irritating, so I still don't like this solution.
回答1:
This should do the trick
erl -noshell -eval 'c:ls()' -eval 'init:stop()'
You have to tell the vm to shut down.
回答2:
you need to specify -noshell and invoke halt() at the end. For instance
erl -noshell -eval "erlydtl:compile('templates/tictactoe.dtl',tictactoe_dtl,[{out_dir,'ebin'}]),halt()."
来源:https://stackoverflow.com/questions/16871832/erlang-invoking-erl-eval-from-command-line-never-exits