<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
CyBerHigh wrote:
<blockquote cite="mid44CA89A1.70700@gurusnetwork.org" type="cite">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?
<br>
<br>
Thanks
<br>
CyBerHigh
<br>
<br>
</blockquote>
Read the 'erl' man page, this can be done with the '-s' or '-run' flag:<br>
<br>
-run Mod [Fun [Args]]:<br>
Passes the -run flag to the init:boot() routine.<br>
<br>
-s Mod [Fun [Args]]:<br>
Passes the -s flag to the init:boot() routine.<br>
<br>
init documentation:<br>
<dl>
<dt><code>-run Module [Function [Args]]</code>
</dt>
<dd> Evaluate the specified function during system initialization. <code>Function</code>
defaults to <code>start</code> and <code>Args</code> to <code>[]</code>.
If the function call ends abnormally, the Erlang runtime system stops
with an error message.<br>
The arguments after <code>-run</code> are used as arguments to Erlang
functions. All arguments are passed as strings. For example:<br>
<pre>$ <strong>erl -run foo -run foo bar -run foo bar baz 1 2</strong>
</pre>
This starts the Erlang runtime system and then evaluates the following
Erlang functions:<br>
<pre>foo:start()
foo:bar()
foo:bar(["baz", "1", "2"]).
</pre>
The functions are executed sequentially in the initialization process,
which then terminates normally and passes control to the user. This
means that a <code>-run</code> call which does not terminate will
block further processing; to avoid this, use some variant of <code>spawn</code>
in such cases.<br>
</dd>
<dt><code>-s Module [Function [Args]]</code>
</dt>
<dd> Evaluate the specified function during system initialization. <code>Function</code>
defaults to <code>start</code> and <code>Args</code> to <code>[]</code>.
If the function call ends abnormally, the Erlang runtime system stops
with an error message.<br>
The arguments after <code>-s</code> are used as arguments to Erlang
functions. All arguments are passed as atoms. For example:<br>
<pre>$ <strong>erl -s foo -s foo bar -s foo bar baz 1 2</strong>
</pre>
This starts the Erlang runtime system and then evaluates the following
Erlang functions:<br>
<pre>foo:start()
foo:bar()
foo:bar([baz, '1', '2']).
</pre>
The functions are executed sequentially in the initialization process,
which then terminates normally and passes control to the user. This
means that a <code>-s</code> call which does not terminate will block
further processing; to avoid this, use some variant of <code>spawn</code>
in such cases.<br>
Due to the limited length of atoms, it is recommended that <code>-run</code>
be used instead.</dd>
</dl>
<br>
</body>
</html>