2

I have a simple Erlang command that I want to invoke via erl -eval (to compile erlydtl template, as described on erlydtl page).

When I do it interactively from shell everything works fine and the command exits immediately:

erl -pa ebin deps\erlydtl\ebin Eshell V5.9.3.1  (abort with ^G) 
1> erlydtl:compile('templates/tictactoe.dtl',tictactoe_dtl,[{out_dir,'ebin'}]).
ok

But when I try to do it via erl -eval (I want to run this from .bat file):

erl -pa ebin deps\erlydtl\ebin -noshell -eval erlydtl:compile('templates/tictactoe.dtl',tictactoe_dtl,[{out_dir,'ebin'}])

Then the command does its job (template is compiled) but it doesn't exit and I need to kill the shell process manually with ctrl+c (I'm working under Windows).

I just want the command to compile the template and exit. What may be the problem?

Update:

One solution may be appending exit() invocation at the end of command, but then I end up with following:

erl -pa ebin deps\erlydtl\ebin -noshell -eval erlydtl:compile('templates/tictactoe.dtl',tictactoe_dtl,[{out_dir,'ebin'}]),exit(success).
{"init terminating in do_boot",success}

Crash dump was written to: erl_crash.dump
init terminating in do_boot (success)

The error message is very irritating, so I still don't like this solution.

Piotr Sobczyk
  • 6,443
  • 7
  • 47
  • 70
  • Alternatively, you can build your project with rebar. It supports Erlydtl template compilation when put under /templates dir. – Ward Bekker Jun 01 '13 at 11:24
  • I currently use rebar but looking for alternative, because rebar compile works very long. – Piotr Sobczyk Jun 01 '13 at 13:13
  • Is `rebar compile skip_deps=true` also slow for you? – Ward Bekker Jun 02 '13 at 10:53
  • 1
    @WardBekker Thanks for your interest, Ward! Yes I know about `skip_deps=true` and I was using it. But it takes like 5 seconds or so for `rebar compile skip_deps=true` to complete on my very small toy project, even if nothing was changed since previous build! And since it's toy project, I need to do compile-run cycles very often. Compiling using `erl -make` takes less than 1 second for me and only edited files are recompiled, so I decided I will switch to it and write quick small script for compiling erlydtl templates. And here we are :-). – Piotr Sobczyk Jun 02 '13 at 13:51

2 Answers2

9

This should do the trick

erl -noshell -eval 'c:ls()' -eval 'init:stop()'

You have to tell the vm to shut down.

Jan Henry Nystrom
  • 1,045
  • 5
  • 8
-1

you need to specify -noshell and invoke halt() at the end. For instance

erl -noshell -eval "erlydtl:compile('templates/tictactoe.dtl',tictactoe_dtl,[{out_dir,'ebin'}]),halt()."
Odobenus Rosmarus
  • 5,870
  • 2
  • 18
  • 21
  • 1
    On the whole I would advice against using halt since that amounts to crashing your way out. The preferred way is to terminate the BEAM by calling init:stop/0 since that allows for any clean up necessary by the applications. In this instance it will make the whole execution a bit slower, but using erlang:halt/0 as the first port of call is a bad habit. I have seen otherwise skilled Erlang programmers waste hours in debugging simply because they have got into the habit of using erlang:halt/0. – Jan Henry Nystrom Jun 02 '13 at 09:17