12

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?

LtWorf
  • 7,286
  • 6
  • 31
  • 45

2 Answers2

21

You can do:

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

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

Chris
  • 947
  • 6
  • 10
  • 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'? – VincentHuang Sep 20 '16 at 02:30
  • 2
    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'. – VincentHuang Sep 20 '16 at 03:10
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.

0xAX
  • 20,957
  • 26
  • 117
  • 206
  • {"init terminating in do_boot",{undef,[{cc,start,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}} – LtWorf Apr 30 '13 at 15:09
  • 1
    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. – Vinod May 01 '13 at 06:46