[erlang-questions] Passing arguments to erlang from the command line

Logan, Martin Martin.Logan@REDACTED
Mon Nov 20 20:59:12 CET 2006


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@REDACTED).
arg = martin@REDACTED
ok
2>


---------- from the command line  ------------

martinjlogan@REDACTED:~$ erl -run test test martin@REDACTED
Erlang (BEAM) emulator version 5.4.12 [source] [hipe]

arg = ["martin@REDACTED"]
Eshell V5.4.12  (abort with ^G)


See the problem? :) 


Cheers,
Martin



-----Original Message-----
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Andy Khan
Sent: Friday, November 17, 2006 5:01 PM
To: erlang-questions@REDACTED
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@REDACTED

I get the following output:

=ERROR REPORT==== 17-Nov-2006::16:55:37 ===
Error in process <0.34.0> on node 'ping@REDACTED' 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@REDACTED)1> pingpong:start_ping(pong@REDACTED).

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
erlang-questions@REDACTED
http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list