Escript: setting code code relative to script directory

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

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

The path is interpreted relative to the directory from which I am running escript, which makes it useless to set the path relative to the location of the script.

My current โ€œworkaroundโ€ uses an absolute path that is annoying as it is all part of the repository, and I don't want it to depend on location.

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

+7
source share
1 answer

I just found out myself:

At the beginning of the main code, add the following code:

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

I recommend always testing true with these code functions, because it is easy to type code:add_pathsz , which wants a list of lines and always returns ok , even if you pass it only a line, but it does not set the code path to a single directory (which is quite annoying btw).

+17
source

All Articles