[erlang-questions] Erlang executable that reads command line arguments

Frederic BONFANTI <>
Fri Oct 16 01:41:25 CEST 2015


Hi,

I'm getting weird error message when calling my escript from within a Python script

escript: exception error: undefined function getopt:parse/2

From the shell a standalone script works just fine... any idea ?

This is how I generate the escripted version of myapp :

#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname make_myapp
main(_) ->	{ok, SourceCode} = file:read_file("myapp.erl"),
		{ok, _, BeamCode} = compile:file("myapp.erl", [binary, debug_info]),
		{ok, _, GetOpt} = compile:file("getopt.erl", [binary, debug_info]),
		escript:create("myapp", [shebang, {archive, [
					{"myapp.erl", SourceCode},
					{"myapp.beam", BeamCode},
					{"getopt.beam",GetOpt}],
					[]}
					]).

Thanks in advance

> On Oct 11, 2015, at 5:40 AM, Dmitry Kolesnikov <> wrote:
> 
> And if you are using rebar and you have deps to other projects you might add following lines to rebar.config
> {escript_incl_apps, [ getopt ]}.
>  {escript_emu_args, "%%! +K true +P 10000000\n"}.
> Sad story, I've not figure out how to add erlang runtime to same package. Anyone, who receives you script needs to have one.
> 
> Best Regards,
> Dmitry
> >-|-|-(*>
> 
> On 11 Oct 2015, at 08:46, Frederic BONFANTI < <mailto:>> wrote:
> 
>> Hi guys,
>> 
>> given a simple Erlang code that consists in one file, let’s say test123.erl , I’d like to 
>> 
>> 1. use a Makefile to compile test123.erl into test.beam and then generate a distributable version of test123 (executable)
>> 
>> 2. figure-out how to parse the command line arguments once this test command is called from regular shell, for example:
>>        
>>        test123 -A -x 555
>> 
>> If there are straightforward examples available, that will do.
>> 
>> Thanks in advance
>> 
>> _______________________________________________
>> erlang-questions mailing list
>>  <mailto:>
>> http://erlang.org/mailman/listinfo/erlang-questions <http://erlang.org/mailman/listinfo/erlang-questions>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151015/9fd3933d/attachment.htm>


More information about the erlang-questions mailing list