[erlang-questions] How to start an erlang applications from the command line non-interactively?

Jarrod Roberson jarrod@REDACTED
Mon May 5 23:54:53 CEST 2008


On Mon, May 5, 2008 at 5:36 PM, Edwin Fine <erlang-questions_efine@REDACTED>
wrote:

> > I have a function start(Port, Htdocs) that I want to call with 8888,
> > "C:/htdocs" and I can't figure out what the appropriate syntax should
> be.
> This can be nasty to get right. It depends on how the command line
> interprets characters like single quote and double quote.
> It also depends on whether you use -s or -run.
>
> -s interprets all function arguments as atoms, so your program will
> get all the values as atoms. You will usually need to write a special
> MFA to convert the atoms to the actual types of the parameters
> desired. Note that all arguments get passed in a single list when
> called like this (see start_cmd_line/3).
>
> -run interprets all function arguments as strings, so your program
> will get all the values as string. You will often have to write a
> special MFA to convert the strings to the actual types of the
> parameters desired.
>
> For example:
>
> -module(foo).
> -export([start_cmd_line/1, start/3]).
>
> start_cmd_line([NameAtom, IntValue, StrValue]) when is_atom(NameAtom),
> is_atom(IntValue), is_atom(StrValue) ->
>    Name = NameAtom, % Not really necessary because NameAtom is already an
> atom
>    Int = list_to_integer(atom_to_list(IntValue)), % Could throw an
> exception
>    Str = atom_to_list(StrValue),
>    start(Name, Int, Str).
>
> start(Name, Int, Str) ->
>    io:format("Name: ~p, Int: ~p, Str: ~p~n", [Name, Int, Str]),
>   % Etc
>   ok.
>
> If you started the above by
>
> erl -s foo Jarrod 12345 "This is a string"
>
> you would get an output something like this:
> Erlang (BEAM) emulator version 5.6.2 [source] [64-bit] [smp:4]
> [async-threads:0] [hipe] [kernel-poll:false]
>
> Name: 'Jarrod', Int: 12345, Str: "This is a string"
> Eshell V5.6.2  (abort with ^G)
> 1>
>
> Hope this helps.
>

thanks that clears things up greatly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080505/5141d5ee/attachment.htm>


More information about the erlang-questions mailing list