[erlang-questions] How can I turn a working escript into erl-shell?

Gleb Peregud <>
Tue Nov 11 14:44:24 CET 2008


Take a look at erl_call. It allows sending commands to the node (the
'rex' server) from the bash command line or script. It is also
probably much faster then erl -eval '...' and does not appear in
nodes().

BR

On 11/10/08, Edwin Fine <> wrote:
> Sergey,
>
> I use bash together with the -eval command-line option. I find this gives me
> great flexibility because I can embed Erlang code directly in my shell
> script and enjoy the benefits of both bash and escript. It took a while to
> get the magical incantations right, but now it works like a charm. If I need
> to talk to an application on another node, I can do so as you say using rpc.
> And, of course, starting a shell is trivial from bash.
>
> For example, here's a Bash shell function I use:
>
> kill_node() {
>     echo "Node ${ERL_NODE_NAME} did not shut down when asked nicely, now
> halting it."
>     ${ERL_CMD} -noshell -noinput -boot ${CLEAN_BOOT_FILE} -sname ${USER}$$ \
>         -eval '
>             Node = '''${ERL_NODE_NAME}''',
>             rpc:call(Node, erlang, halt, [], 3000),
>             init:stop(). '
> }
>
> ERL_CMD uses erlexec directly, e.g.
>
> export ROOTDIR=...
> export BINDIR=...
> ERL_CMD="${BINDIR}/erlexec -config ${CONFIG_FILE}"
>
> Regards,
> Edwin
>
> On Mon, Nov 10, 2008 at 11:40 AM, Sergey A. <> wrote:
>
>> Hello.
>>
>> As I known there are two well-known approaches for writing a comand
>> line interface for an erlang program: using escript and bash.
>>
>> I've chose escript as the language for writing my first interface.
>>
>> I hope it will be useful to see the source for somebody who is writing
>> escript interface now. It's here:
>>
>> http://gist.github.com/23516
>>
>> Now about the question I have. With bash I can turn a working script
>> into any program just by calling something like:
>>
>> erl -sname dbg -remsh myapp # <-- this starts the Erlang shell and
>> tell it to connect to a remote node. After the shell will be closed,
>> script will continue
>>
>> Thus, the bash script can be used both as a tool for manipulating a
>> working Erlang application (you can call rpc:call, or smth like) and
>> as a tool for opening Erlang shell with all the arguments passed
>> (which is very useful when debugging. It just make life easy).
>>
>> Is there any way to open the erlang shell from an escript?
>>
>> Thanks.
>>
>> --
>> Sergey.
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>>
>


-- 
Gleb Peregud
http://gleber.pl/

Every minute is to be grasped.
Time waits for nobody.
-- Inscription on a Zen Gong



More information about the erlang-questions mailing list