"escript: no such file or directory:" error

13,734

Solution 1

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!

Solution 2

** 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

Share:
13,734
z_axis
Author by

z_axis

e^(π.i) + 1 = 0

Updated on June 04, 2022

Comments

  • z_axis
    z_axis almost 2 years

    %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 ?

  • z_axis
    z_axis over 12 years
    thanks for your quick answer. But it indeed doesnot work here.
  • z_axis
    z_axis over 12 years
    >whereis escript escript: /usr/local/bin/escript >echo $PATH /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/us‌​r/local/bin
  • Muzaaya Joshua
    Muzaaya Joshua over 12 years
    you could run a find command like this: $ sudo find / -name "escript"
  • Iain Samuel McLean Elder
    Iain Samuel McLean Elder over 10 years
    Worked for me. I "installed" Erlang using kerl. I have to run the activate script before I can use erl or escript in the terminal.