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

Dave Cottlehuber <>
Fri Jan 11 15:48:49 CET 2013


Hi Fredrik,

Thanks for looking at this. Magnus has proposed a more general patch:

http://permalink.gmane.org/gmane.comp.lang.erlang.patches/3273

I'm happy to withdraw mine in favour of his.

Thanks
Dave

On 11 January 2013 15:22, Fredrik <> wrote:
> Hello Dave,
> Could you submit your patch this way:
> https://github.com/erlang/otp/wiki/submitting-patches and scroll down to
> "Sending the patch"
> Thanks!
>
> BR Fredrik Gustafsson
> Erlang OTP Team
>
> On 12/18/2012 12:14 PM, Dave Cottlehuber wrote:
>
> Bumping, is there anything you'd like differently so this could go
> into R16 please?
>
> Gist has been updated according to the thread,
> https://gist.github.com/4189389ecd2bf1ca8163 I am not confident I have
> the whitespacing right, the escript.c style seems to vary a lot.
>
> We are very close to escript perfection on Windows!
>
> A+
> Dave
>
> On 27 November 2012 14:40, Dave Cottlehuber <> 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
> 
> http://erlang.org/mailman/listinfo/erlang-patches
>
>


More information about the erlang-patches mailing list