2013-09-27 51 views
0

我試圖使用init:get_argument(master)爲名稱'master'獲取標誌的值,它給了我一個崩潰轉儲。但是,如果我將「主」更改爲「猴」,那麼工作正常。主人是保留國旗嗎?init:get_argument在標誌爲主時給出崩潰轉儲

我在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,[]]}}}) 

回答

3

-master標誌實際使用Erlang的內核file I/O on slave nodes

應該避免將標誌傳遞給erl,儘管可能並記錄在案。您應該使用簡單參數或應用程序環境值。在後一種情況下,你的命令行是:

$ erl -pa ebin -testerl master value

而且你將與application:get_env/1,2,3檢索值。環境值也可以嵌入到發行版使用的系統配置文件中(如果遵循OTP設計原則)。