When I start up a function within the erl shell, it works fine. When I try to invoke the same function with 开发者_JAVA百科erl ... -s module function, it fails.
The line of code that eventually fails is:
start(Port) ->
mochiweb_http:start([{port, Port}, {loop, fun dispatch_requests/1}]).
I'm positive that Port is set correctly. My error message is:
=CRASH REPORT==== 17-Jan-2010::00:21:09 ===
crasher:
initial call: mochiweb_socket_server:acceptor_loop/1
pid: <0.65.0>
registered_name: []
exception exit: {error,closed}
in function mochiweb_socket_server:acceptor_loop/1
ancestors: [mochiweb_http,<0.1.0>]
messages: []
links: []
dictionary: []
trap_exit: false
status: running
heap_size: 377
stack_size: 24
reductions: 93
neighbours:
I tried the debugger and it lets me step through right up until the line of code above is given. After I pass that, it gives me this crash report.
Any help is greatly appreciated.
Hm, I think that should work. Are all modules compiled with the same compiler version? IIRC there might be weird errors on the socket level if not. BTW, you might call your entry point function start which is the default for -s.
Alternatively you can try the -eval
option:
erl -eval 'module:start(9090).'
when using -s, the arguments are collected into a list, so the port would actually be enclosed in a list. you can check both cases (list or int) with a wrapper function (like start([Port])
).
When you use -s to run Erlang functions, arguments are put into a list of atoms. When you use -run to run Erlang functions, arguments are put into a list of strings.
If you need an integer value to pass on, you will need to do the proper conversions. If you want to cover all cases, something like this could help:
start([Port]) when is_atom(Port) ->
start([atom_to_list(Port)]);
start([Port]) when is_list(Port) ->
start(list_to_integer(Port));
start(Port) when is_integer(Port) ->
mochiweb_http:start([{port, Port}, {loop, fun dispatch_requests/1}]).
Consult the man page for erl ("erl -man erl") for details.
精彩评论