start erlang application from command line
Asked Answered
R

2

13

I have an erlang application, compiled with rebar.

Normally I start it with like this:

application:start(myapp).

from inside the erl shell.

Could anyone tell me how to start it like a normal command line program?

Rett answered 30/4, 2013 at 14:46 Comment(1)
Some of the answers to this question might help.Paramilitary
R
21

You can do:

erl -pa ebin -eval "application:start(myapp)"

If you want it to run in the background, add -noshell -detached

Rupiah answered 30/4, 2013 at 20:31 Comment(2)
In my codes, I have 'application:get_env()' in start function and I got {badmatch, undefined} error returned by using -eval "application:start(myapp)". Is there any other library path I should include like '-pa'?Middleoftheroader
Oh, I answer my self question above. If you want to get some environment variable which is define in 'etc/app.confg', don't forget to include it by using '-config etc/app.config'.Middleoftheroader
C
8

Create shell script, something like that:

exec erl -pa ebin/ deps/*/ebin -s myapp

Other options which you need see http://www.erlang.org/doc/man/erl.html.

Coattail answered 30/4, 2013 at 15:3 Comment(2)
{"init terminating in do_boot",{undef,[{cc,start,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}Rett
for erl -s myapp to work you need to write a function in your myapp.erl as start() -> application:start(myapp). -s option is to call the MFA. By default it calls start without passing parameters if only module name is specified.Peahen

© 2022 - 2024 — McMap. All rights reserved.