开发者

starting erlang application with parameter

Is there a way to pass parameters to root supervisor of an application other than with config file and application:get_env/1? For instance, by command line?

I start my app as "erl -pa ebin -run appname", and then communicate with it by TCP/IP. TCP port on which it listens is set in ebin/appname.app, in env part. Now I'd like to be able to tell my app to forget that and 开发者_JAVA技巧listen on a port which I would give on command line (something like "erl -pa ebin -run appname -env [{port, 1234}]"). Is there a standardised pattern for that?

The problem is that I sometimes decide the app should start on another, non default port, for testing purposes, and changing the .app file every time is just pain in the ass.

Regards, dijxtra


Yes. You can override the value of an environment variable via the command line, using:

erl -appname key value

And retrieving the parameter using:

application:get_env(appname, key).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜