简体   繁体   中英

Escript: setting code path relative to script directory

When I try to set a relative code path in a escript with -pz like this

#!/usr/bin/env escript
%% -*- erlang -*-
%%! -pz ../dir-of-some-beams

The path is interpreted relative to the directory from where I run the escript from, which renders it useless for setting the path relative to the script location.

My current "workaround" is using a absolute path which is annoying since all this is part of a repository and I don't want it to be location dependent.

So how can I set the code path relative to the directory the escript is located in?

Just found it out myself:

At the beginning of main add code like this:

true = code:add_pathz(filename:dirname(escript:script_name()) 
                       ++ "/../dir-of-some-beams"),

I recommend always testing for true whith these code functions, because its easy to type code:add_pathsz which wants a list of strings and always returns ok , even if you pass it just a string -- but it doesn't set the code path to the single directory (which is pretty annoying behaviour btw).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM