Erlang VM -s 参数行为不当
当我在 erl shell 中启动一个函数时,它工作正常。当我尝试使用 erl ... -s 模块函数调用相同的函数时,它失败了。
最终失败的代码行是:
start(Port) ->
mochiweb_http:start([{port, Port}, {loop, fun dispatch_requests/1}]).
我确信端口设置正确。我的错误消息是:
=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:
我尝试了调试器,它让我可以单步执行,直到给出上面的代码行。在我通过之后,它给了我这个崩溃报告。
非常感谢任何帮助。
When I start up a function within the erl shell, it works fine. When I try to invoke the same function with 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯,我认为这应该可行。
所有模块都使用相同的编译器版本编译吗? IIRC 如果没有的话,套接字级别可能会出现奇怪的错误。
顺便说一句,您可以将入口点函数称为 start,这是 -s 的默认值。
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.
或者,您可以尝试
-eval
选项:Alternatively you can try the
-eval
option:当使用 -s 时,参数被收集到一个列表中,因此端口实际上会包含在一个列表中。您可以使用包装函数(如
start([Port])
)检查这两种情况(list 或 int)。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])
).当您使用 -s 运行 Erlang 函数时,参数将被放入原子列表中。当您使用 -run 运行 Erlang 函数时,参数将放入字符串列表中。
如果您需要传递整数值,则需要进行适当的转换。如果您想涵盖所有情况,类似这样的内容可能会有所帮助:
有关详细信息,请参阅 erl(“erl -man erl”)的手册页。
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:
Consult the man page for erl ("erl -man erl") for details.