代码之家  ›  专栏  ›  技术社区  ›  Eli

Erlang VM-S参数行为错误

  •  0
  • Eli  · 技术社区  · 15 年前

    当我在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:
    

    我尝试了调试器,它让我可以直接执行,直到给出上面的代码行。我通过后,它给了我这个车祸报告。

    非常感谢您的帮助。

    4 回复  |  直到 8 年前
        1
  •  1
  •   andi5    15 年前

    顺便说一句,您可以调用入口点函数start,这是-s的默认值。

        2
  •  1
  •   legoscia    8 年前

    或者您可以尝试 -eval 选项:

    erl -eval 'module:start(9090).'
    
        3
  •  0
  •   jspcal    15 年前

    当使用-s时,参数被收集到一个列表中,因此端口实际上被包含在一个列表中。您可以使用包装函数(比如 start([Port]) )

        4
  •  0
  •   ndim    15 年前

    当使用-s运行erlang函数时,参数将被放入 原子 . 当使用-run运行erlang函数时,参数将被放入 .

    如果你需要一个 整数 如果要传递值,则需要进行正确的转换。如果你想覆盖所有的案例,这样做可以帮助:

    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}]).
    

    查阅手册页 厄尔 详细信息请参阅(“erl-man erl”)。