开发者

starting erlang application with parameter

开发者 https://www.devze.com 2023-04-11 19:28 出处:网络
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?

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

精彩评论

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