starting erlang app from command line
Håkan Stenholm
hokan.stenholm@REDACTED
Sat Jul 29 00:56:09 CEST 2006
CyBerHigh wrote:
> I was wondering if it was possible to start an erlang app from the
> command line. Like a simple shell script you would just put in the
> shebang and mark it as executable then run it. However this doesn't
> seem to be possible with erlang. Anything I write seems to have to be
> done from the erlang shell. Are there any workarounds?
>
> Thanks
> CyBerHigh
>
Read the 'erl' man page, this can be done with the '-s' or '-run' flag:
-run Mod [Fun [Args]]:
Passes the -run flag to the init:boot() routine.
-s Mod [Fun [Args]]:
Passes the -s flag to the init:boot() routine.
init documentation:
|-run Module [Function [Args]]|
Evaluate the specified function during system initialization.
|Function| defaults to |start| and |Args| to |[]|. If the function
call ends abnormally, the Erlang runtime system stops with an error
message.
The arguments after |-run| are used as arguments to Erlang
functions. All arguments are passed as strings. For example:
$ *erl -run foo -run foo bar -run foo bar baz 1 2*
This starts the Erlang runtime system and then evaluates the
following Erlang functions:
foo:start()
foo:bar()
foo:bar(["baz", "1", "2"]).
The functions are executed sequentially in the initialization
process, which then terminates normally and passes control to the
user. This means that a |-run| call which does not terminate will
block further processing; to avoid this, use some variant of |spawn|
in such cases.
|-s Module [Function [Args]]|
Evaluate the specified function during system initialization.
|Function| defaults to |start| and |Args| to |[]|. If the function
call ends abnormally, the Erlang runtime system stops with an error
message.
The arguments after |-s| are used as arguments to Erlang functions.
All arguments are passed as atoms. For example:
$ *erl -s foo -s foo bar -s foo bar baz 1 2*
This starts the Erlang runtime system and then evaluates the
following Erlang functions:
foo:start()
foo:bar()
foo:bar([baz, '1', '2']).
The functions are executed sequentially in the initialization
process, which then terminates normally and passes control to the
user. This means that a |-s| call which does not terminate will
block further processing; to avoid this, use some variant of |spawn|
in such cases.
Due to the limited length of atoms, it is recommended that |-run| be
used instead.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060729/57f98ff0/attachment.htm>
More information about the erlang-questions
mailing list