Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function of erlang file from shell script

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

like image 953
Geek Avatar asked Feb 12 '26 10:02

Geek


1 Answers

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

#!/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 calls main/1 function of the script but you can pass function name as an argument to call it

main([Fun]) ->
    FunAtom = list_to_atom(Fun),
    ?MODULE:FunAtom().
like image 198
Lol4t0 Avatar answered Feb 14 '26 00:02

Lol4t0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!