gen_server:cast from escript

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

gen_server:cast from escript

YuanZhiqian
Hi guys,

  I was trying to call gen_server:cast from a escript file, everything that used to work well in erl shell won't work in escript, I have no idea what made the difference, here is the code, could anyone help me to find a clue? 



#!/usr/bin/env escript

%%! -name bk@test -setcookie budget_keeper

main(Argv) ->
    {Node, File} = case Argv of
                       [] ->
                           {'budget_keeper@127.0.0.1', "cache"};
                       [F] ->
                           {'budget_keeper@127.0.0.1', F};
                       [N, F] ->
                           {N, F}
                   end,
    io:format("~p ~p ~p ~p~n", [node(), erlang:get_cookie(), Node, File]),
    gen_server:cast({bk_main, Node}, {dump_data, File}).



As shown above, the target process is called "bk_main" which is on the node 'budget_keeper@127.0.0.1', I have run the same code in erl shell, and bk_main can get the notice, but nothing happened when I ran the same code in this script.

Best regards
Zhiqian

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: gen_server:cast from escript

Park, Sungjin-2
You didn't connect to target node.
Have to call net_adm:ping(Node) first to connect.



On Tue, Mar 8, 2016 at 3:47 PM, YuanZhiqian <[hidden email]> wrote:
Hi guys,

  I was trying to call gen_server:cast from a escript file, everything that used to work well in erl shell won't work in escript, I have no idea what made the difference, here is the code, could anyone help me to find a clue? 



#!/usr/bin/env escript

%%! -name bk@test -setcookie budget_keeper

main(Argv) ->
    {Node, File} = case Argv of
                       [] ->
                           {'[hidden email]', "cache"};
                       [F] ->
                           {'[hidden email]', F};
                       [N, F] ->
                           {N, F}
                   end,
    io:format("~p ~p ~p ~p~n", [node(), erlang:get_cookie(), Node, File]),
    gen_server:cast({bk_main, Node}, {dump_data, File}).



As shown above, the target process is called "bk_main" which is on the node '[hidden email]', I have run the same code in erl shell, and bk_main can get the notice, but nothing happened when I ran the same code in this script.

Best regards
Zhiqian

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




--
Park, Sungjin
-------------------------------------------------------------------------------------------------------------------
Peculiar travel suggestions are dancing lessons from god.
  -- The Books of Bokonon
-------------------------------------------------------------------------------------------------------------------

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: gen_server:cast from escript

YuanZhiqian
Hi Park,

  Thanks a lot. That works! I wonder, however, why it is needed to connect to target node manually in an escript, while in a shell I can directly execute gen_server:cast to another target node.

Regards
Zhiqian


Date: Thu, 10 Mar 2016 12:35:21 +0900
Subject: Re: [erlang-questions] gen_server:cast from escript
From: [hidden email]
To: [hidden email]
CC: [hidden email]

You didn't connect to target node.
Have to call net_adm:ping(Node) first to connect.



On Tue, Mar 8, 2016 at 3:47 PM, YuanZhiqian <[hidden email]> wrote:
Hi guys,

  I was trying to call gen_server:cast from a escript file, everything that used to work well in erl shell won't work in escript, I have no idea what made the difference, here is the code, could anyone help me to find a clue? 



#!/usr/bin/env escript

%%! -name bk@test -setcookie budget_keeper

main(Argv) ->
    {Node, File} = case Argv of
                       [] ->
                           {'[hidden email]', "cache"};
                       [F] ->
                           {'[hidden email]', F};
                       [N, F] ->
                           {N, F}
                   end,
    io:format("~p ~p ~p ~p~n", [node(), erlang:get_cookie(), Node, File]),
    gen_server:cast({bk_main, Node}, {dump_data, File}).



As shown above, the target process is called "bk_main" which is on the node '[hidden email]', I have run the same code in erl shell, and bk_main can get the notice, but nothing happened when I ran the same code in this script.

Best regards
Zhiqian

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




--
Park, Sungjin
-------------------------------------------------------------------------------------------------------------------
Peculiar travel suggestions are dancing lessons from god.
  -- The Books of Bokonon
-------------------------------------------------------------------------------------------------------------------

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions