Return value of a function in Erlang

后端 未结 1 1007
野的像风
野的像风 2021-01-18 08:12

What the following function will return? ok atom or Cmd?

function_test() ->
    Cmd = os:cmd(\"ls\"),
    io:format(\"The result of ls is:~p~n\", [Cmd]).
         


        
相关标签:
1条回答
  • 2021-01-18 08:57

    In Erlang the last expression in your function is returned, in your case that would be the result of io:format which is ok.

    To return Cmd you can simply make it the last expression in your function:

    function_test() ->
        Cmd = os:cmd("ls"),
        io:format("The result of ls is:~p~n", [Cmd]),
        Cmd.
    
    0 讨论(0)
提交回复
热议问题