Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"escript: no such file or directory:" error

Tags:

erlang

%cat fact

#!/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).

%./fact "5"

escript: no such file or directory: './fact'

%whereis escript

escript: /usr/bin/escript

%pacman -Qi erlang

name   : erlang version  : R14B04-1

Why doesnot escript run "fact" ?


On my Archlinux box, escript still doesnot work !

%cat hello.erl 
main(_) -> io:fwrite("~p~n", "hello,world!").

%escript hello.erl 
escript: no such file or directory: 'hello.erl'

%whereis escript 
escript: /usr/bin/escript

%ls -l /usr/bin/escript
lrwxrwxrwx 1 root root 25 12月 18 17:37 /usr/bin/escript -> ../lib/erlang/bin/escript*

%/usr/lib/erlang/bin/escript hello.erl 
escript: no such file or directory: 'hello.erl'

%strace -f -F -o aaa.txt /usr/lib/erlang/bin/escript hello.erl 
escript: no such file or directory: 'hello.erl
%cat aaa.txt
execve("/usr/lib/erlang/bin/escript", ["/usr/lib/erlang/bin/escript", "hello.erl"], [/* 40 vars */]) = 0
...
open("hello.erl", O_RDONLY|O_LARGEFILE) = 3
...
execve("/usr/lib/erlang/bin/erl", ["/usr/lib/erlang/bin/erl", "+B", "-boot", "start_clean", "-noshell", "-run", "escript", "start", "-extra", "hello.erl"], [/* 40 vars */]) = 0.
...
stat64("hello.erl", 0xb5a44d90)   = -1 ENOENT (No such file or directory)
open("hello.erl", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
......

Why does it use "stat64" instead of "stat" ? I am using 32 bits system.

%uname -a
Linux myarch 3.1.5-1-ARCH #1 SMP PREEMPT Sun Dec 11 06:26:14 UTC 2011 i686 AMD Athlon(tm) 64 X2 Dual Core Processor 3600+ AuthenticAMD GNU/Linux
%erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 5.8.5

Sincerely!


%ls
fact*
%escript fact "5" 
escript: no such file or directory: 'fact'
%escript fact 5  
escript: no such file or directory: 'fact

%ls -l /usr/bin/escript 
lrwxrwxrwx 1 root root 25 10月 15 03:24 /usr/bin/escript -> ../lib/erlang/bin/escript*

Strange problem ?

like image 582
z_axis Avatar asked Oct 18 '25 07:10

z_axis


2 Answers

** NOTE * This answer is customized for Windows Users, but can be understood and useful to other opertaing system users

Is escript in the $PATH environment variable ? usually its hidden in ERTS_PATH/bin where ERTS_PATH is in C:\Program Files (x86)\erl5.8.4\erts-5.8.4\ in Windows 7. look for the equivalent on Linux or Unix or MAC for erts. add this path (C:\Program Files (x86)\erl5.8.4\erts-5.8.4\bin) to the $PATH. escript should be able to work anywhere

like image 86
Muzaaya Joshua Avatar answered Oct 20 '25 17:10

Muzaaya Joshua


The reason is VERY simple. Because the following line is in ~/.erlang:

file:set_cwd("/media/D/www/qachina/db/doc/erlang")

so that escript will change the current directory once executed. The escript works great after removing that line.

Best Regards!

like image 45
z_axis Avatar answered Oct 20 '25 15:10

z_axis