将args通过rebar shell传递给erl?
Posted
技术标签:
【中文标题】将args通过rebar shell传递给erl?【英文标题】:Pass args through rebar shell to erl? 【发布时间】:2016-01-27 09:54:04 【问题描述】:我正在使用“rebar shell”来测试我的应用程序。这被记录为:
启动一个预先加载项目和deps的shell,类似于
'erl -pa ebin -pa deps/*/ebin'.
如何在“erl”的底层调用中添加额外的参数?为了 例如,我想添加应用程序特定的环境变量和 运行一个模块/函数。我想调用类似的东西:
erl -pa ebin -pa deps/*/ebin -browser_spy browser_exe "/my/dir" -run bs_example test
(我希望 code:priv_dir 像使用 rebar shell 时一样工作, 上面的 'erl' 命令没有这样做)。
【问题讨论】:
【参考方案1】:你不能
rebar shell
实际上并不执行erl ...
命令,而只是尝试复制其行为。
实际上,rebar 只是通过添加带有code:add_pathz
的路径来模仿-pa
将自己变成外壳
实现细节见here:
shell(_Config, _AppFile) -> true = code:add_pathz(rebar_utils:ebin_dir()), %% scan all processes for any with references to the old user and save them to %% update later NeedsUpdate = [Pid || Pid <- erlang:processes(), proplists:get_value(group_leader, erlang:process_info(Pid)) == whereis(user) ], %% terminate the current user ok = supervisor:terminate_child(kernel_sup, user), %% start a new shell (this also starts a new user under the correct group) _ = user_drv:start(), %% wait until user_drv and user have been registered (max 3 seconds) ok = wait_until_user_started(3000), %% set any process that had a reference to the old user's group leader to the %% new user process _ = [erlang:group_leader(whereis(user), Pid) || Pid <- NeedsUpdate], %% enable error_logger's tty output ok = error_logger:swap_handler(tty), %% disable the simple error_logger (which may have been added multiple %% times). removes at most the error_logger added by init and the %% error_logger added by the tty handler ok = remove_error_handler(3), %% this call never returns (until user quits shell) timer:sleep(infinity).
【讨论】:
以上是关于将args通过rebar shell传递给erl?的主要内容,如果未能解决你的问题,请参考以下文章
如何告诉 rebar3 在 Windows 上使用 werl?