简体   繁体   English

从Shell脚本调用erlang文件的功能

[英]Calling a function of erlang file from shell script

我有一个文件xyz.erl,其中包含一个功能fun1。我想从linux脚本中调用它。

You can create escript from your file. 您可以从文件中创建脚本 Follow the instructions 遵循指示

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. 然后,您可以将erlang脚本称为常规脚本。 Note that you still required Erlang runtime installed to execute script. 请注意,您仍然需要安装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().

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM