|
Hi,
I'm playing with the pingpong example in the tutorial, and I'm trying to launch the ping process directly from the command line. When I run the program as follows: >erl -sname ping -run pingpong start_ping pong@bmt71 I get the following output: =ERROR REPORT==== 17-Nov-2006::16:55:37 === Error in process <0.34.0> on node 'ping@bmt71' with exit value: {badarg,[{pingpong,ping,2}]} However, if I first start the erlang shell and then invoke the start_ping method, everying works fine: >erl -sname ping Eshell V5.5.2 (abort with ^G) (ping@bmt71)1> pingpong:start_ping(pong@bmt71). I must be missing something about passing arguments from the command line (I've shown my hacked about version of the ping code below). Can anybody help? Regards Andy ping(N, Pong_Node) -> {pong, Pong_Node} ! {ping, self()}, io:format("ping waiting for input~n", []), receive pong -> io:format("Ping received pong~n", []) end, ping(N - 1, Pong_Node). start_ping(Pong_Node) -> spawn(pingpong, ping, [3, Pong_Node]). _______________________________________________ erlang-questions mailing list [hidden email] http://www.erlang.org/mailman/listinfo/erlang-questions |
|
Andy Khan <[hidden email]> writes:
> Hi, > > I'm playing with the pingpong example in the tutorial, and I'm trying to > launch the ping process directly from the command line. When I run the > program as follows: > >>erl -sname ping -run pingpong start_ping pong@bmt71 > >From the erl man page: -run 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 strings. See init(3). So pong@bmt71 ends up being a string. How about using -eval "pingpong:start_ping(pong@bmt71)" Jani Hakala _______________________________________________ erlang-questions mailing list [hidden email] http://www.erlang.org/mailman/listinfo/erlang-questions |
|
In reply to this post by Andy Khan
I wrote a small script to show you why this does not work
-module(test). -export([test/1]). test(Arg) -> io:format("arg = ~p~n", [Arg]). I will first invoke the script from the erl shell and then from the command line with the run option as you do. ---------- from the command shell ------------ 1> test:test(martin@logan). arg = martin@logan ok 2> ---------- from the command line ------------ martinjlogan@core:~$ erl -run test test martin@logan Erlang (BEAM) emulator version 5.4.12 [source] [hipe] arg = ["martin@logan"] Eshell V5.4.12 (abort with ^G) See the problem? :) Cheers, Martin -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Andy Khan Sent: Friday, November 17, 2006 5:01 PM To: [hidden email] Subject: [erlang-questions] Passing arguments to erlang from the command line Hi, I'm playing with the pingpong example in the tutorial, and I'm trying to launch the ping process directly from the command line. When I run the program as follows: >erl -sname ping -run pingpong start_ping pong@bmt71 I get the following output: =ERROR REPORT==== 17-Nov-2006::16:55:37 === Error in process <0.34.0> on node 'ping@bmt71' with exit value: {badarg,[{pingpong,ping,2}]} However, if I first start the erlang shell and then invoke the start_ping method, everying works fine: >erl -sname ping Eshell V5.5.2 (abort with ^G) (ping@bmt71)1> pingpong:start_ping(pong@bmt71). I must be missing something about passing arguments from the command line (I've shown my hacked about version of the ping code below). Can anybody help? Regards Andy ping(N, Pong_Node) -> {pong, Pong_Node} ! {ping, self()}, io:format("ping waiting for input~n", []), receive pong -> io:format("Ping received pong~n", []) end, ping(N - 1, Pong_Node). start_ping(Pong_Node) -> spawn(pingpong, ping, [3, Pong_Node]). _______________________________________________ erlang-questions mailing list [hidden email] http://www.erlang.org/mailman/listinfo/erlang-questions _______________________________________________ erlang-questions mailing list [hidden email] http://www.erlang.org/mailman/listinfo/erlang-questions |
| Powered by Nabble | Edit this page |
