Escript:设置相对于脚本目录的代码路径 [英] Escript: setting code path relative to script directory
问题描述
当我尝试用这样的pz设置一个与pz相关的代码路径
#!/ usr / bin / env escript
%% - * - erlang - * -
%%! -pz ../dir-of-some-beams
路径相对于目录我在这里运行escript,这使得它无法用于设置相对于脚本位置的路径。
我目前的解决方法正在使用一个令人讨厌的绝对路径所有这些都是存储库的一部分,我不希望它与位置相关。
那么如何设置代码路径相对于目录所在的目录在
刚刚发现自己:
开始这样的主要添加代码:
true = code:add_pathz(filename:dirname(escript:script_name())
++/../dir-of-some-beams),
我推荐总是测试 true
这些代码
函数,因为它很容易键入代码:add_pathsz
它需要字符串和alw的列表ays返回 ok
,即使你只传递一个字符串 - 但是它没有将代码路径设置为单个目录(这是令人讨厌的行为btw)。 / p>
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).
这篇关于Escript:设置相对于脚本目录的代码路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!