Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

starting erlang application with parameter

Tags:

erlang

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

like image 710
dijxtra Avatar asked Oct 10 '11 14:10

dijxtra


People also ask

How do I start an Erlang project?

On a Unix system you enter the command erl at the operating system prompt. This command starts the Erlang runtime system and the Erlang shell. On the Windows platform you normally start Erlang/OTP from the start menu. You can also enter the command erl or werl from a DOS box or Command box.

What is an Erlang application?

Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecoms, banking, e-commerce, computer telephony and instant messaging.

What is behavior in Erlang?

Behaviours are formalizations of these common patterns. The idea is to divide the code for a process in a generic part (a behaviour module) and a specific part (a callback module). The behaviour module is part of Erlang/OTP.


1 Answers

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).
like image 66
Roberto Aloi Avatar answered Sep 28 '22 02:09

Roberto Aloi