dijxtra
dijxtra

Reputation: 2751

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 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

Upvotes: 6

Views: 1626

Answers (1)

Roberto Aloi
Roberto Aloi

Reputation: 31015

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).

Upvotes: 10

Related Questions