[erlang-questions] starting application after a set_env variable

Michal Ptaszek <>
Sat Jun 20 11:33:08 CEST 2009


Hello Roberto,

.app file is read when you load the application into
your system, that is - during its start. 
The env variables from the .app override their previous 
values - so you will not find their original value anymore.

However, there is a simple workaround - try something like
that:
application:load(my_app). %% here you will load also the .app file
application:set_env(my_app, Key, Val).
application:start(my_app). %% .app will not be parsed here

----- "Roberto Ostinelli" <> wrote:

> dear all,
> 
> i'm starting an application which i need to dinamically configure.
> 
> therefore, in the my_app.app file, i set an empty list as env:
> 
> {application, my_app,
> [
> 	{description, "My App"},
> 	{vsn, "0.3"},
> [...]
> 	{env, []},
> 	{mod, {my_app, []}}
> ]}.
> 
> then, before starting the application, i set the env variables i need,
>  
> with:
> 
> application:set_env(my_app, var1, "value").
> 
> then i start the application with application:start(my_app), and in  
> the start/2 function of my_app i have:
> 
> start(_Type, _StartArgs) ->
> 	{ok, Var1} = application:get_env(my_app, var1),
> 	my_sup:start_link(Var1).
> 
> so, basically i use Var1 as parameter of my_sup, which is my top level
>  
> supervisor.
> 
> i can see that Var1 is correct within my_app:start/2, because if i  
> print it out it corresponds to the string "value".
> 
> however, the application fails to start, and i get the following:
> 
> {error,{shutdown,{my_app,start,[normal,[]]}}}
> 
> =INFO REPORT==== 20-Jun-2009::11:12:35 ===
>      application: my_app
>      exited: {shutdown,{my_app,start,[normal,[]]}}
>      type: temporary
> 
> if, instead, i set the var1 in the my_app.app file, without changing 
> 
> ANYTHING in the code, everything works correctly:
> 
> {application, my_app,
> [
> 	{description, "My App"},
> 	{vsn, "0.3"},
> [...]
> 	{env, [{var1, "value"}]},
> 	{mod, {my_app, []}}
> ]}.
> 
> 
> is there some kind soul to tell me what i'm doing wrong?
> 
> thank you in advance,
> 
> r.
> 
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org

Best regards,
-- 
Michal Ptaszek
www.erlang-consulting.com


More information about the erlang-questions mailing list