arguments after --

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Wed Aug 31 14:15:58 CEST 2005


Snipped from the 'erl' documentation:

  "-- 
	Any arguments following -- will not be interpreted in any way.
	They can be retrieved by init:get_plain_arguments/0. 
	The exception is arguments starting with a +, which will be
	interpreted as system flags (see below). "

but some experimentation shows that it doesn't work as advertised:

$ erl -boot start_clean -sname foo 
Erlang (BEAM) emulator version 5.4.7 [hipe] [threads:0] [kernel-poll]

Eshell V5.4.7  (abort with ^G)
(foo@REDACTED)1> application:get_env(kernel,net_ticktime).
undefined
(foo@REDACTED)2> 
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
a
$ erl -boot start_clean -sname foo -kernel net_ticktime 60
Erlang (BEAM) emulator version 5.4.7 [hipe] [threads:0] [kernel-poll]

Eshell V5.4.7  (abort with ^G)
(foo@REDACTED)1> application:get_env(kernel,net_ticktime).
{ok,60}
(foo@REDACTED)2> 
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
a
$ erl -boot start_clean -sname foo -- -kernel net_ticktime 60
Erlang (BEAM) emulator version 5.4.7 [hipe] [threads:0] [kernel-poll]

Eshell V5.4.7  (abort with ^G)
(foo@REDACTED)1> application:get_env(kernel,net_ticktime).
{ok,60}
(foo@REDACTED)2> init:get_plain_arguments().
[]
(foo@REDACTED)3> 


My conclusion was that erlexec uses "--" to separate the 
automatically generated options from the user options.
But all these options end up in init:get_arguments() anyway,
so I'm unsure as to what it accomplishes.

There is also an "-extra" option, which is supposed to do
exactly the same thing as "--" is supposed to do. "-extra"
_does_ work exactly as advertised.


The included patches suggest a way to address the problem.

First, change erlexec.c so that it doesn't overload "--":

*** /home/etxuwig/OSE/tmp/otp_src_R10B-7/erts/etc/common/erlexec.c      Tue Mar 22 15:09:54 2005
--- erlexec.c   Wed Aug 31 14:04:11 2005
***************
*** 675,681 ****
      add_Eargs(rootdir);
      add_Eargs("-progname");
      add_Eargs(progname);
!     add_Eargs("--");
      ensure_EargsSz(EargsCnt + argsCnt + 1);
      for (i = 0; i < argsCnt; i++)
        Eargsp[EargsCnt++] = argsp[i];
--- 675,681 ----
      add_Eargs(rootdir);
      add_Eargs("-progname");
      add_Eargs(progname);
!     add_Eargs("-end");
      ensure_EargsSz(EargsCnt + argsCnt + 1);
      for (i = 0; i < argsCnt; i++)
        Eargsp[EargsCnt++] = argsp[i];

Then, change init.erl, so that it recognizes "-end":

ws12858> gdiff -c ~/OSE/tmp/otp_src_R10B-7/lib/kernel/src/init.erl init.erl
*** /home/etxuwig/OSE/tmp/otp_src_R10B-7/lib/kernel/src/init.erl        Tue May 10 17:08:13 2005
--- init.erl    Wed Aug 31 14:06:46 2005
***************
*** 1055,1061 ****
  check(<<"-s">>) -> start_arg;
  check(<<"-run">>) -> start_arg2;
  check(<<"-eval">>) -> eval_arg;
! check(<<"--">>) -> end_args;
  check(X) when binary(X) ->
      case binary_to_list(X) of
        [$-|_Rest] -> flag;
--- 1055,1062 ----
  check(<<"-s">>) -> start_arg;
  check(<<"-run">>) -> start_arg2;
  check(<<"-eval">>) -> eval_arg;
! check(<<"-end">>) -> end_args;
! check(<<"--">>) -> start_extra_arg;
  check(X) when binary(X) ->
      case binary_to_list(X) of
        [$-|_Rest] -> flag;


/Uffe



More information about the erlang-bugs mailing list