简体   繁体   English

用参数启动erlang应用程序

[英]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? 有没有办法将参数传递给除了配置文件和应用程序之外的应用程序的根管理程序: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. 我将我的应用程序作为“erl -pa ebin -run appname”启动,然后通过TCP / IP与它通信。 TCP port on which it listens is set in ebin/appname.app, in env part. 它侦听的TCP端口在env part中的ebin / appname.app中设置。 Now I'd like to be able to tell my app to forget that and listen on a port which I would give on command line (something like "erl -pa ebin -run appname -env [{port, 1234}]"). 现在,我希望能够告诉我的应用程序忘记这一点,并在一个我将在命令行上提供的端口上侦听(类似“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. 问题是我有时会决定应用程序应该从另一个非默认端口开始,以进行测试,并且每次更改.app文件只是痛苦的屁股。

Regards, dijxtra 此致,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).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM