erl in unix pipe?

76 views
Skip to first unread message

Anthony Howe

unread,
Jan 21, 2022, 9:19:25 AM1/21/22
to erlang-questions@erlang.org Questions
I've not had occasion before now to try to use erl in a unix pipe. I want to
find the OTP major release for a shell script.

First attempt almost works but spits out a termination message that unix tools
do not. Plus the shell version and prompts are present; no quiet option.

elf$ echo 'erlang:system_info(compat_rel).'| erl
Eshell V11.2.2 (abort with ^G)
1> 23
2> *** Terminating erlang (nonode@nohost)


I found -noshell, so I try assorted, which print nothing and don't quit:

elf$ echo 'erlang:system_info(compat_rel).'| erl -noshell
^C
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
(l)oaded (v)ersion (k)ill (D)b-tables (d)istribution

elf$ echo 'erlang:system_info(compat_rel). init:stop().'| erl -noshell
^C
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
(l)oaded (v)ersion (k)ill (D)b-tables (d)istribution

elf$ echo 'erlang:system_info(compat_rel), init:stop().'| erl -noshell
^C
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
(l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
elf$ echo 'io:format("~p~n",[system_info(compat_rel))]).'| erl -noshell -s init stop
elf$

Google some and I find try:

elf$ erl -noshell -s erlang system_info compat_rel
{"init terminating in
do_boot",{badarg,[{erlang,system_info,[[compat_rel]],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot
({badarg,[{erlang,system_info,[[_]],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]})

Crash dump is being written to: erl_crash.dump...done
elf$


How does one pipe Erlang statements into erl and pipe the output?

Wishes Erlang (erl) behaved more like unix tools.

--
Anthony C Howe
ach...@snert.com BarricadeMX & Milters
http://snert.com/ http://nanozen.snert.com/ http://snertsoft.com/

2QdxY4Rz...@potatochowder.com

unread,
Jan 21, 2022, 9:27:11 AM1/21/22
to erlang-q...@erlang.org
On 2022-01-21 at 09:19:09 -0500,
Anthony Howe <ach...@snert.com> wrote:

> How does one pipe Erlang statements into erl and pipe the output?
>
> Wishes Erlang (erl) behaved more like unix tools.

Try writing an escript:

https://www.erlang.org/doc/man/escript.html
https://erlang.org/documentation/doc-5.7.4/erts-5.7.4/doc/html/escript.html

rebar3 supports escripts, too.

Anthony Howe

unread,
Jan 21, 2022, 9:31:42 AM1/21/22
to erlang-q...@erlang.org
I've written escripts in the past for command line tools, but in this case I
just want to use one or two lines to query settings without having to write a
full script.

Anthony Howe

unread,
Jan 21, 2022, 9:34:39 AM1/21/22
to andrei zavada, erlang-questions@erlang.org Questions
On 2022-01-21 09:30, andrei zavada wrote:
> Have a look how this can be
> done: https://github.com/hmmr/riak_cs/blob/develop-3.0/Makefile#L9
> <https://github.com/hmmr/riak_cs/blob/develop-3.0/Makefile#L9>. The crucial
> point here is to call halt at the end. Also, using display (and not io:format)
> helps the output to go to stdout (exactly why is not something I can explain,
> though). I stole it from some other project.

Ohh! That did the trick. Thanks.

erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell
Reply all
Reply to author
Forward
0 new messages