[erlang-patches] escript does not parse supplied vm args on Windows

Håkan Mattsson hm@REDACTED
Wed Nov 28 09:57:55 CET 2012


If you want to extend the escript syntax it does not suffice to
just fix escript.c. Besides documentation and test suites, you
need to fix ALL code that is dependent of the escript syntax,
such as the functions escript:create/2 and escript:extract/2.

/Håkan

On Tue, Nov 27, 2012 at 2:40 PM, Dave Cottlehuber <dch@REDACTED> wrote:
> On Windows,  the vmargs are not passed through from the 2nd or 3rd
> line of the escript file if the shebang syntax is not the unix shell
> style. Which it often isn't, as you'd expect.
>
> On unix, this produces the expected output of init-debug before requesting beer:
>
> ## ./icanhaz
>
>     #!/usr/bin/env escript
>     %% -*- erlang -*-
>     %%! -init_debug -smp enable
>     main(_) -> io:format("I CAN HAZ BEER?~n", []).
>
> On Windows, only the BEER is requested:
>
> ## icanhaz.cmd
>
>     @echo off & setlocal & path=%~dp0;%path%; & escript.exe
> "%~dpn0.cmd" %* & goto :eof
>     %% -*- erlang -*-
>     %%! -init_debug -smp enable
>     main(_) -> io:format("I CAN HAZ BEER?~n", []).
>
> NB: the somewhat cryptic sequence above tells a windows .cmd script to
> suppress printing the batch file commands as they are processed, so
> this @ would be a very common approach on windows. The path juggling
> inside allows you distribute an escript with a NIF-based DLL alongside
> in the same directory and have it "just work" without altering the
> system or shell path.
>
> Here's a small patch, accepting that the @ format is common on windows
> https://gist.github.com/4189389ecd2bf1ca8163
>
> diff --git i/erts/etc/common/escript.c w/erts/etc/common/escript.c
> index 9e80ec6..dcb1c85 100644
> --- i/erts/etc/common/escript.c
> +++ w/erts/etc/common/escript.c
> @@ -264,7 +264,8 @@ append_shebang_args(char* scriptname)
>         static char linebuf[LINEBUFSZ];
>         char* ptr = fgets(linebuf, LINEBUFSZ, fd);
>
> -       if (ptr != NULL && linebuf[0] == '#' && linebuf[1] == '!') {
> +       /* Acceptable Shebang syntax is #/ for unix or @ for windows */
> +       if (ptr != NULL && ((linebuf[0] == '#' && linebuf[1] == '!') ||
> linebuf[0] == '@')) {
>             /* Try to find args on second or third line */
>             ptr = fgets(linebuf, LINEBUFSZ, fd);
>             if (ptr != NULL && linebuf[0] == '%' && linebuf[1] == '%' &&
> linebuf[2] == '!') {
>
> NBB: the whitespace in escript.c is inconsistent. The patch reflects this.
>
> NBBB: This yak was brought to you fully shaved whilst trying to
> understand why `-detached` wasn't working in escript on Windows.
>
> A+
> Dave
> _______________________________________________
> erlang-patches mailing list
> erlang-patches@REDACTED
> http://erlang.org/mailman/listinfo/erlang-patches



More information about the erlang-patches mailing list