Erlang中文手册(Erldoc.com)  »  net_adm  »  host_file/0
Erlang并发编程 Erlang/OTP设计原理 Erlang/OTP[pdf] Mnesia用户手册[pdf] Erlang完整手册[en] 官网手册[en] 模块列表 方法列表 随机 Erlang中文社区(BBS) 美女图库

net_adm:host_file/0

读取 .hosts.erlang 文件

用法:

host_file() -> Hosts | {error, Reason}

内部实现:

-spec host_file() -> Hosts | {error, Reason} when
      Hosts :: [Host :: atom()],
      %% Copied from file:path_consult/2:
      Reason :: file:posix() | badarg | terminated | system_limit
              | {Line :: integer(), Mod :: module(), Term :: term()}.

host_file() ->
    Home = case init:get_argument(home) of
	       {ok, [[H]]} -> [H];
	       _ -> []
	   end,
    case file:path_consult(["."] ++ Home ++ [code:root_dir()], ".hosts.erlang") of
	{ok, Hosts, _} -> Hosts;
	Error -> Error
    end.

读取文件 .hosts.erlang,文件里的 hosts 数据 以一个列表返回,如果文件不能被堵,或者文件里的 Erlang 项(terms)不能被解析,则返回 {error, Reason}。

net_adm:host_file().
阿里云 - 最高1000元通用代金券立即可用
沪ICP备13037221号-9