从shell脚本调用erlang文件的函数

时间:2022-08-08 16:03:36

I have a file xyz.erl which contains a function fun1.I want want to call it from linux script.Any pointers?

我有一个文件xyz。erl包含函数fun1。我想从linux脚本中调用它。指针吗?

1 个解决方案

#1


3  

You can create escript from your file. Follow the instructions

您可以从您的文件创建escript。按照说明

In brief, you should add call instructions for the shell and erlang to the begginig of you file

简而言之,您应该在文件的“乞丐”中添加shell和erlang的调用指令

#!/usr/bin/env escript
%% -*- erlang -*-

Then make file executable.

然后文件执行。

Then you can call erlang script as conventional script. Note that you still required Erlang runtime installed to execute script.

然后您可以调用erlang脚本作为常规脚本。注意,仍然需要安装Erlang运行时来执行脚本。

Erlang calls main/1 function of the script but you can pass function name as an argument to call it

Erlang调用脚本的main/1函数,但可以将函数名作为参数传递给它

main([Fun]) ->
    FunAtom = list_to_atom(Fun),
    ?MODULE:FunAtom().

#1


3  

You can create escript from your file. Follow the instructions

您可以从您的文件创建escript。按照说明

In brief, you should add call instructions for the shell and erlang to the begginig of you file

简而言之,您应该在文件的“乞丐”中添加shell和erlang的调用指令

#!/usr/bin/env escript
%% -*- erlang -*-

Then make file executable.

然后文件执行。

Then you can call erlang script as conventional script. Note that you still required Erlang runtime installed to execute script.

然后您可以调用erlang脚本作为常规脚本。注意,仍然需要安装Erlang运行时来执行脚本。

Erlang calls main/1 function of the script but you can pass function name as an argument to call it

Erlang调用脚本的main/1函数,但可以将函数名作为参数传递给它

main([Fun]) ->
    FunAtom = list_to_atom(Fun),
    ?MODULE:FunAtom().