从makefile启动erlang otp应用程序
我已经创建了一个erlang应用程序,在这里我可以使用application:start(Name)成功启动该应用程序 我尝试创建一个makefile步骤,使用rebar进行编译,然后手动启动应用程序。但它似乎不起作用。以下是我现在拥有的:从makefile启动erlang otp应用程序,erlang,Erlang,我已经创建了一个erlang应用程序,在这里我可以使用application:start(Name)成功启动该应用程序 我尝试创建一个makefile步骤,使用rebar进行编译,然后手动启动应用程序。但它似乎不起作用。以下是我现在拥有的: all: compile start compile: ./rebar compile start: erl -s application load shoutcast -s application start shoutcast 所有
all: compile start
compile:
./rebar compile
start:
erl -s application load shoutcast -s application start shoutcast
所有这一切只是加载一个交互式erlang shell
Aplication:start(Name)
召唤
Name:start/2
当-s标志调用
Name:start() or Name:start([arg1, arg2, ...]).
所以,我认为您不能以这种方式成功地调用应用程序。假设您不想创建发行版和启动文件,您可以(我认为)向应用程序模块添加一个方法start/0
-module(shoutcast).
-behaviour(application).
%% Application callbacks
-export([start/2, stop/1]).
%% Allow for erl -s invocation
-export([start/0]).
... Snip ...
start() ->
application:start(shoutcast).
... Snip ...
然后在makefile中
erl -s shoutcast
我不确定这是否违反了最佳实践,但它应该有效 最好将有用的东西保存在公共Makefile中
将-s的第三个参数(本例中为shoutcast)作为列表发送。因此,您的代码将调用application:start([shoutcast]),但它不起作用。您可以编写一个函数来实现这一点,或者考虑创建一个发行版。我一直在寻找“适当”的方法来实现这一点,但这实际上符合我的需要,因此对此表示感谢。我认为这是可以接受的,离标准也不远。例如,cowboy示例包括只公开start/0的模块,而start/0又调用application:start(cowboy)。见:()