[erlang-questions] Passing command line options to erlang programs

Garrett Smith g@REDACTED
Tue Oct 26 18:16:39 CEST 2010


You might also consider using escript, which is better suited for
running console based Erlang apps, IMO.

Here's a simple tutorial that uses getopt, but also covers escript:

http://erlware.blogspot.com/2010/10/console-applications-in-erlang.html

On Tue, Oct 26, 2010 at 1:52 AM, Bengt Kleberg
<bengt.kleberg@REDACTED> wrote:
> Greetings,
>
> Please look at the erl manual page:
> http://erlang.org/doc/man/erl.html
>
> There you will find that all flags (arguments with - first) are for the
> Erlang part of the runtime system.
>
> However, there are -extra and -- which both may be what you are looking
> for.
>
>
> bengt
>
>
> On Tue, 2010-10-26 at 07:43 +0200, Muharem Hrnjadovic wrote:
>> Hello,
>>
>> I am fairly new to erlang, so please forgive me if this is a stupid
>> question :-)
>>
>> I am trying to pass command line options to the following erlang program:
>> {{{
>> -module(demo).
>> -export([main/1]).
>>
>> main(Args) -> io:format("~p~n", [Args]).
>> }}}
>>
>> When only passing command line *arguments* everything works as expected:
>>
>> {{{
>> $ erl -noshell -s demo main a b c -s init stop
>> [a,b,c]
>> }}}
>>
>> But when passing command line *options* things break
>>
>> {{{
>> $ erl -noshell -s demo main a -b c -s init stop
>> [a]
>> $ erl -noshell -s demo main -a b c -s init stop
>> {"init terminating in
>> do_boot",{undef,[{demo,main,[]},{init,start_it,1},{init,start_em,1}]}}
>>
>> Crash dump was written to: erl_crash.dump
>> init terminating in do_boot ()
>> }}}
>>
>> Is there another way to sneak options past erl? Or is the code above
>> broken in some other way?
>> If no, then maybe erl needs an option passing/escape mechanism like e.g.
>> gcc's "-Wl" ..?
>>
>> When using an escript file BTW things works as one would expect.
>>
>> Best regards/Mit freundlichen Grüßen
>>
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list