[erlang-questions] why not works command from shell

Sergey Safarov s.safarov@REDACTED
Tue Dec 13 22:07:56 CET 2016


Thank you Hugo
I created wrapper

[root@REDACTED test]# cat test.erl
-module(test).
-export([lookup/0, lookup_wait/0]).

lookup() ->
    io:format("Called lookup~n"),
    Result = inet_res:nslookup('example.org',in,a),
    io:format("Finished lookup. Result: ~p~n", [Result]).

lookup_wait() ->
    timer:sleep(5000),
    io:format("Called lookup_wait~n"),
    Result = inet_res:nslookup('example.org',in,a),
    io:format("Finished lookup_wait. Result: ~p~n", [Result]).


And get following results.
NXDOMAIN for lookup call.

[root@REDACTED test]# erl -noshell -run test lookup
Called lookup
Finished lookup. Result: {error,nxdomain}

Correct resolv when called lookup_wait.

[root@REDACTED test]# erl -noshell -run test lookup_wait
Called lookup_wait
Finished lookup_wait. Result: {ok,
                               {dns_rec,
                                {dns_header,1,true,query,false,false,true,
                                 true,false,0},
                                [{dns_query,"example.org",a,in}],
                                [{dns_rr,"example.org",a,in,0,81792,
                                  {93,184,216,34},
                                  undefined,[],false}],
                                [{dns_rr,"example.org",ns,in,0,81791,
                                  "a.iana-servers.net",undefined,[],false},
                                 {dns_rr,"example.org",ns,in,0,81791,
                                  "b.iana-servers.net",undefined,[],false}],
                                [{dns_rr,"a.iana-servers.net",a,in,0,168191,
                                  {199,43,135,53},
                                  undefined,[],false},
                                 {dns_rr,"a.iana-servers.net",aaaa,in,0,
                                  168191,
                                  {8193,1280,143,0,0,0,0,83},
                                  undefined,[],false},
                                 {dns_rr,"b.iana-servers.net",a,in,0,168191,
                                  {199,43,133,53},
                                  undefined,[],false},
                                 {dns_rr,"b.iana-servers.net",aaaa,in,0,
                                  168191,
                                  {8193,1280,141,0,0,0,0,83},
                                  undefined,[],false}]}}


Why resolv not work first five second of program start? What to do to
resolv this issue?

Sergey


вт, 13 дек. 2016 г. в 23:47, Hugo Mills <hugo@REDACTED>:

> On Tue, Dec 13, 2016 at 07:52:48PM +0000, Sergey Safarov wrote:
> > When executed following command from erl shell all works as expected
> >
> > 1> inet_res:nslookup('example.org','in','a').
>
> inet_res:nslookup/3
>
> > [root@REDACTED ~]# erl -noshell -s inet_res nslookup 'example.org' 'in'
> 'a'
> > {"init terminating in do_boot",{undef,[{inet_res,nslookup,[['example.org
> > ',in,a]],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
> > init terminating in do_boot ()
>
> "         -s Mod [Func [Arg1, Arg2, ...]](init flag):
>
>            Makes init call the specified function.  Func defaults to
>            start. If no arguments are provided, the function is
>            assumed to be of arity 0. Otherwise it is assumed to be of
>            arity 1, taking the list [Arg1,Arg2,...]  as argument.  All
>            arguments are passed as atoms. See init(3erl).
> "
>
>    Note the fourth sentence: "Otherwise it is assumed to be of arity 1
> [...]"
>
> so you're actually calling
>
> inet_res:nslookup(['example.org', in, a]) (which doesn't exist)
>
>    Hugo.
>
> --
> Hugo Mills             | Two things came out of Berkeley in the 1960s: LSD
> hugo@REDACTED carfax.org.uk | and Unix. This is not a coincidence.
> http://carfax.org.uk/  |
> PGP: E2AB1DE4          |
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161213/33c8e35c/attachment.htm>


More information about the erlang-questions mailing list