Hi all,<div><br></div><div>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.</div>
<div><br></div><div>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).</div><div>
<br></div><div>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).</div><div>
<br></div><div>Here's a copy of my session, using the escript reference manual example:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>
C:\tmp>set PATHEXT</div></div><div><div>PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.py;.tcl;.PSC1;.erl</div></div><div><div><br></div></div><div><div>C:\tmp>factorial 5</div></div><div><div>usage: factorial integer</div>
</div><div><div><br></div></div><div><div>C:\tmp>cat factorial.erl</div></div><div><div>#!/usr/bin/env escript</div></div><div><div>%% -*- erlang -*-</div></div><div><div>%%! -smp enable -sname factorial -mnesia debug verbose</div>
</div><div><div>main([String]) -></div></div><div><div> try</div></div><div><div> N = list_to_integer(String),</div></div><div><div> F = fac(N),</div></div><div><div> io:format("factorial ~w = ~w\n", [N,F])</div>
</div><div><div> catch</div></div><div><div> _:_ -></div></div><div><div> usage()</div></div><div><div> end;</div></div><div><div>main(_) -></div></div><div><div> usage().</div></div><div>
<div>usage() -></div></div><div><div> io:format("usage: factorial integer\n"),</div></div><div><div> halt(1).</div></div><div><div>fac(0) -> 1;</div></div><div><div>fac(N) -> N * fac(N-1).</div></div>
<div><div><br></div></div><div><div>C:\tmp>escript factorial 5</div><div>escript: Failed to open file: c:\pg\erl\bin\escript.escript</div><div><br></div><div>C:\tmp></div></div><div><div>C:\tmp>escript.exe factorial.erl 5</div>
</div><div><div>factorial 5 = 120</div></div><div><div><br></div></div><div><div>C:\tmp>which escript.exe</div></div><div><div>c:/pg/erl/bin/escript.exe</div></div></blockquote><div><br></div><div><br><div class="gmail_quote">
<div> 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.</div><div>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</div>
<div><br></div><div>The only way I can get it to work is to invoke it like this: "escript.exe factorial 5"</div><div><br></div><div>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.</div>
<div><br></div><div>Is this behaviour intentional or am I missing something?</div><div><br></div><div>Thanks!</div></div><br></div><div><br></div><div>-- Pierre Rouleau</div>