目前我的 Erlang 应用程序是在一个 escript(TCP 服务器)中启动的,并且一切正常,因为它使用我提供的默认端口。现在我想通过 escript 将端口传递给应用程序,但我不知道如何。(该应用程序运行一个主管)
脚本.escript
!/usr/bin/env escript
%% -*- erlang -*-
-export([main/1]).
main([UDPort, TCPort]) ->
U = list_to_integer(UDPort),
T = list_to_integer(TCPort),
app:start(), %% Want to pass T into the startup.
receive
_ -> ok
end;
...
应用程序.erl
-module(app).
-behaviour(application).
-export([start/0, start/2, stop/0, stop/1]).
-define(PORT, 4300).
start () -> application:start(?MODULE). %% This is called by the escript.
stop () -> application:stop(?MODULE).
start (_StartType, _StartArgs) -> supervisor:start(?PORT).
stop (_State) -> ok.
老实说,我不确定使用应用程序是否可以做到这一点,但我认为最好问一下。