Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting environment variables in Erlang applications

There's clearly something I don't understand about Erlang... well, among many things.

I've set up an application under Rebar called cw.I start it up and everything runs fine.

Now I want to create an environment variable so I can access the src directory. I've entered the following in cw.app.src:

{env, [{proj_root, "mypath/apps/cw"}]}

Compile, start with Rebar start.sh... everything works fine.

Now the mystery. Yesterday when I did this, I got the correct path when I entered application:get_env(cw, proj_root) in the Erlang shell. But today I get undefined.

What am I missing?

Many thanks,

LRP

like image 527
Lloyd R. Prentice Avatar asked Oct 21 '25 16:10

Lloyd R. Prentice


2 Answers

application:load(cw) should be enough.

like image 59
filmor Avatar answered Oct 25 '25 07:10

filmor


Did you forget application:start(cw) first? If application not started, the env is undefined.

like image 24
goofansu Avatar answered Oct 25 '25 08:10

goofansu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!