Launch erlang application with parameter

Is there a way to pass parameters to the root supervisor of the application other than the configuration file and the application: get_env / 1? For example, on the command line?

I run my application as "erl -pa ebin -run appname" and then communicate with it via TCP / IP. The TCP port on which it is listening is set to ebin / appname.app, to env part. Now I would like to tell my application to forget about it and listen to the port that I would give on the command line (something like "erl -pa ebin -run appname -env [{port, 1234}]"). Is there a standardized template for this?

The problem is that I sometimes decide that the application should start from a different port, and not by default, for testing and changing the .app file every time is just a pain in the ass.

Regards, dijxtra

+6
source share
1 answer

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

erl -appname key value 

And extracting the parameter with:

 application:get_env(appname, key). 
+8
source

Source: https://habr.com/ru/post/898980/


All Articles