[erlang-questions] Bug in escript when running under Windows?

Pierre Rouleau prouleau001@REDACTED
Sat Jun 4 19:47:25 CEST 2011


Hi all,

I am new to Erlang.  While learning it, I started writing Erlang scripts
running them with escript.   One of the very nice feature of Erlang is that
it is cross platform. My escript files run fine in *nix boxes.
 Unfortunately the implementation under Windows seems buggy: the ".exe"
extension must be placed after escript for the script to work.

That prevents using Windows PATHEXT capability which would allow launching
an Erlang escript file by simply giving its base name (like I can do it for
Python scripts on Windows for example).

On a Windows computer I added .erl to PATHEXT to get CMD to search for the
.erl file.  I also associated the .erl file to the escript.exe file ( on
that computer it's c:/pg/erl/bin.escript.exe).

Here's a copy of my session, using the escript reference manual example:

C:\tmp>set PATHEXT
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.py;.tcl;.PSC1;.erl

C:\tmp>factorial 5
usage: factorial integer

C:\tmp>cat factorial.erl
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname factorial -mnesia debug verbose
main([String]) ->
    try
        N = list_to_integer(String),
        F = fac(N),
        io:format("factorial ~w = ~w\n", [N,F])
    catch
        _:_ ->
            usage()
    end;
main(_) ->
    usage().
usage() ->
    io:format("usage: factorial integer\n"),
    halt(1).
fac(0) -> 1;
fac(N) -> N * fac(N-1).

C:\tmp>escript factorial 5
escript: Failed to open file: c:\pg\erl\bin\escript.escript

C:\tmp>
C:\tmp>escript.exe factorial.erl 5
factorial 5 = 120

C:\tmp>which escript.exe
c:/pg/erl/bin/escript.exe



 As you can see, the first invocation, "factorial 5", is able to run the
script, but the arguments are not passed properly to the script.
The second invocation, "escript factorial 5" seems to indicate a bug in
escript as it is looking for the file c:\pg\erl\bin\escript.escript

The only way I can get it to work is to invoke it like this: "escript.exe
factorial 5"

If there is one thing I like on Windows, it's the ability to invoke a script
by type the script name without the extension and the interpreter name.

Is this behaviour intentional or am I missing something?

Thanks!


-- Pierre Rouleau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110604/69e1e70d/attachment.htm>


More information about the erlang-questions mailing list