0

我试图使用 init:get_argument(master) 获取名为“master”的标志的值,这给了我一个崩溃转储。但是,如果我将“master”更改为“monkey”,则一切正常。master 是保留标志吗?

我在 Windows 7 32 位上运行版本 5.10/OTP R16。这是我使用的代码:

-module(testerl_app).

-behaviour(application).

%% Application callbacks
-export([start/2, stop/1]).

%% ===================================================================
%% Application callbacks
%% ===================================================================

start(_StartType, _StartArgs) ->
    case init:get_argument(master) of
        {ok, CLIFlag} ->
            io:format("*** info command flag master has value ~p~n", [CLIFlag]);
        _ ->
            io:format("*** info no command flag master~n")
    end,
    testerl_sup:start_link().

stop(_State) ->
    ok.

这是我得到的错误:

C:\Users\xxxx\workspace\testerl>erl -pa ebin -master me -eval "application:start(testerl)"

{error_logger,{{2013,9,27},{10,48,37}},supervisor_report,[{supervisor,{local,ker
nel_sup}},{errorContext,start_error},{reason,{no_master,{badrpc,nodedown}}},{off
ender,[{pid,undefined},{name,file_server_2},{mfargs,{file_server,start_link,[]}}
,{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}
{error_logger,{{2013,9,27},{10,48,37}},crash_report,[[{initial_call,{application
_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0
.9.0>},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,
file_server_2,{no_master,{badrpc,nodedown}}}},{kernel,start,[normal,[]]}},[{appl
ication_master,init,4,[{file,"application_master.erl"},{line,133}]},{proc_lib,in
it_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}},{ancestors,[<0.8.0>]},{me
ssages,[{'EXIT',<0.10.0>,normal}]},{links,[<0.8.0>,<0.7.0>]},{dictionary,[]},{tr
ap_exit,true},{status,running},{heap_size,376},{stack_size,27},{reductions,117}]
,[]]}
{error_logger,{{2013,9,27},{10,48,38}},std_info,[{application,kernel},{exited,{{
shutdown,{failed_to_start_child,file_server_2,{no_master,{badrpc,nodedown}}}},{k
ernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kern
el,{{shutdown,{failed_to_start_child,file_server_2,{no_master,{badrpc,nodedown}}
}},{kernel,start,[normal,[]]}}}"}

Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,kerne
l,{{shutdown,{failed_to_start_child,file_server_2,{no_master,{badrpc,nodedown}}}
},{kernel,start,[normal,[]]}}})
4

1 回答 1

3

-master标志实际上被 Erlang 内核用于从节点上的文件 I/O

erl应避免将标志传递给,尽管可能且已记录在案。您应该使用普通参数或应用程序环境值。在后一种情况下,您的命令行将是:

$ erl -pa ebin -testerl master value

您将使用 检索该值application:get_env/1,2,3。环境值也可以嵌入到版本使用的系统配置文件中(如果您遵循 OTP 设计原则)。

于 2013-09-27T14:54:30.253 回答