无法从命令行启动空OTP应用程序

时间:2013-09-15 06:55:33

标签: erlang

我用钢筋创建了一个OTP应用程序骨架:

$ rebar create-app appid=test

然后我用rebar compile编译它,当我运行

$ erl -pa ebin -s test

我收到此错误

{"init terminating in do_boot",{undef,[{test,start,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}

但是如果我从shell调用start它就可以了:

$ erl -pa ebin

Erlang R15B01 (erts-5.9.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9.1  (abort with ^G)
1> application:start(test).
ok

如何从OS命令行启动应用程序?

编辑:

我认为我需要运行

$ erl -pa ebin -s application start test

现在我没有收到任何错误,但该应用仍然没有开始......

2 个答案:

答案 0 :(得分:2)

erl -pa ebin/ -eval "application:start(test)"

由于start中的test_app.erl函数具有arity 2,因此无法使用erl开关-s(或-run)直接调用它,只有arity 0或1可以使用这些开关调用(参见http://erlang.org/doc/man/erl.html)。

您可以添加一个包装函数,然后调用start/2,但我认为-eval更优雅。

答案 1 :(得分:2)

-s标志假定在显示一个或多个参数时的参数列表。那么$ erl -pa ebin -s application start test所做的就是调用application:start([test]),这将无法正常工作。

这是一种解决方法(可能不是最佳解决方案):

使用以下内容创建源文件src/test_init.erl

-module(test_init).

-compile(export_all).

init() ->
    application:start(test).

然后:

$ rebar compile
$ erl -pa ebin -s test_init init

现在应该运行test应用程序:)