[erlang-questions] application:get_env return undefined

Robert Virding <>
Wed Jan 9 16:06:00 CET 2013


A config file has the syntax: 

[{Application1, [{Par11,Val11},...]}, 
..., 
{ApplicationN, [{ParN1,ValN1},...]}]. 

which means that the application is not specified in the file name but in the data in the actual file. So you can have configuration data for many applications in one file. So in your case you have defined configuration data for the application 'my_app_config' with key1. So if we define our minimal application my_app with config file in my_app.app and app.config: 

$ cat my_app.app 
{application,my_app, 
[{description,"My App"}, 
{env,[{key1,"val .app"}]} 
]}. 
$ cat app.config 
[{my_app,[{key1,"val .config"}]}]. 

Then we can do: 

$ erl 
Erlang R15B (erts-5.9) [source] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false] 

Eshell V5.9 (abort with ^G) 
1> application:start(my_app). 
ok 
2> application:get_env(my_app,key1). 
{ok,"val .app"} 

while: 

$ erl -config app.config 
Erlang R15B (erts-5.9) [source] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false] 

Eshell V5.9 (abort with ^G) 
1> application:start(my_app). 
ok 
2> application:get_env(my_app,key1). 
{ok,"val .config"} 

Check in http://www.erlang.org/doc/design_principles/applications.html 
more specifically: 
http://www.erlang.org/doc/design_principles/applications.html#id74278 

The problem of finding the file still remains of course. 

Robert 

P.S. Got a bit longer than expected here. 

----- Original Message -----

> From: "Alexander 0xAX" <>
> To: 
> Sent: Wednesday, 9 January, 2013 3:39:00 PM
> Subject: Re: [erlang-questions] application:get_env return undefined

> Hello,

> Thank you for replies.

> I try to run my application without .config extenstion:

> exec erl -config app -s test_app

> Same result.

> 2013/1/9 Slava Yurin <  >

> > Hi Alexander.
> 

> > Please see https://github.com/nevar/sys_test .
> 

> > 09.01.2013, 20:14, "Alexander 0xAX" < 
> > >:
> 
> > > Hello,
> > 
> 

> > > I have simple test application with test.app.src file,
> > > test_app.erl
> > > and test_sup.erl
> > 
> 

> > > Also i want to read config in my application. I have app.config:
> > 
> 

> > > [
> > 
> 
> > > {my_app_config,
> > 
> 
> > > [{key1, "val"}]}
> > 
> 
> > > ].
> > 
> 

> > > I run my application:
> > 
> 

> > > erl -boot start_sasl -config app.config -s test_app
> > 
> 

> > > And now, after application successful starting i try to read my
> > > config:
> > 
> 

> > > >application:get_env(test_app, my_app_config).
> > 
> 
> > > undefined
> > 
> 

> > > Why? How can i correctly read config file?
> > 
> 

> > > Thank you.
> > 
> 
> > > ,
> > 
> 
> > > _______________________________________________
> > 
> 
> > > erlang-questions mailing list
> > 
> 
> > > 
> > 
> 
> > > http://erlang.org/mailman/listinfo/erlang-questions
> > 
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130109/818b6f18/attachment.html>


More information about the erlang-questions mailing list