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

Edwin Fine <>
Mon Nov 10 20:29:05 CET 2008


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081110/1a7f35c7/attachment.html>


More information about the erlang-questions mailing list