我已经使用 basho rebar 编译了我的 Erlang 应用程序,它生成了一个独立的 escript 可执行文件。我从命令行运行它,如下所示:
./myapp myconfig.config
我的问题是如何确定运行我的应用程序的 Erlang 节点名称。当我在应用程序中运行“node()”命令时,它默认返回“nonode@nohost”,但我想为该节点提供我的名称(例如[电子邮件受保护] /cdn-cgi/l/email-protection),所以当我在应用程序中运行“node()”时,我喜欢看到“[电子邮件受保护] /cdn-cgi/l/email-protection' 而不是 'nonode@nohost'
我知道“erlang-name”[电子邮件受保护] /cdn-cgi/l/email-protection'”但请考虑我从命令行运行应用程序。我认为 Erlang VM 在应用程序生命周期内自动运行和终止。
最好的方法当然是在命令行中通过“-sname node”或“-name node@host”设置nodename。
但可以使用“net_kernel”模块代替。它描述于http://www.erlang.org/doc/man/net_kernel.html http://www.erlang.org/doc/man/net_kernel.html
$ erl
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.1 (abort with ^G)
1> node().
nonode@nohost
2> net_kernel:start([rumata, shortnames]).
{ok,<0.34.0>}
(rumata@rumata-osx)3> node().
'rumata@rumata-osx'
(rumata@rumata-osx)4> net_kernel:stop().
ok
5> node().
nonode@nohost
6> net_kernel:start(['rumata@myhost', longnames]).
{ok,<0.44.0>}
(rumata@myhost)7> node().
rumata@myhost
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)