Proper way to start an elixir application from command line?

3,072 views
Skip to first unread message

Carlo Cabanilla

unread,
Apr 15, 2012, 1:14:22 PM4/15/12
to elixir-l...@googlegroups.com
Hi,

I'm trying to figure out how to start an elixir app from command line, preferably jumping into an iex session similar to what erl does. Right now as a workaround, I have a module:

defmodule :cerebrate do
@behavior :application
def start() do

end
end

Using an atom as the module name instead of a capitalized name compiles a standard cerebrate.beam file, instead of something within the __MAIN__ directory. From the command line, I call erl -s cerebrate and it starts the application behavior and jumps into an erlang shell. I'd like to instead jump into an iex shell so that I can inspect my modules with elixir syntax. Is that possible?

I tried doing this:

defmodule Cerebrate do
@behavior :application
def start() do

end
end

And then running both elixir -e "Cerebrate.start" --no-halt and iex -e "Cerebrate.start" --no-halt but it seems to just hang without print out any feedback.

.Carlo

José Valim

unread,
Apr 15, 2012, 1:25:04 PM4/15/12
to elixir-l...@googlegroups.com
Both should actually work. Can you post your application or an example somewhere so I can try it out? Thanks.

Carlo Cabanilla

unread,
Apr 15, 2012, 4:47:09 PM4/15/12
to elixir-l...@googlegroups.com
Ah, I figured it out. The .app file is a little quirky. It needs to be named "__MAIN__.Cerebrate.app" and the application and mod atoms of the app file needed to be '__MAIN__.Cerebrate'. Worth documenting or maybe adding a mix task to generate app files automatically.

José Valim

unread,
Apr 15, 2012, 4:52:23 PM4/15/12
to elixir-l...@googlegroups.com
Yes. In the future, we should generate the .app file with Mix using Elixir code as source, so you don't need to worry at all with escaping atoms. :)


José Valim
Founder and Lead Developer

José Valim

unread,
Aug 15, 2012, 7:17:02 AM8/15/12
to elixir-l...@googlegroups.com
We have experienced some other places where io is hanging too.

Could you please push to github an application that reproduces the error? I will debug it and try to come up with a solution.

On Wednesday, August 15, 2012 8:05:20 AM UTC-3, k1complete wrote:
you don't need to make app file that is auto generated in mix.exs(
  def project do
    [ app: Cerebrate,
      version: "x.x.x" ]
  end
  def application do
    [mod: {Cerebrate,[]},
     applications: [:sasl ],
     description: 'Hello Cerebrate Server App']
  end
)
But, The same thing happened to me! this is minimum set.
-----
defmodule App do
  def start do
    :ok = :application.start(:app)
  end
  def start(_type, arg) do
   :gen_server.start_link({:local, :app}, AppSrv, arg, [])
  end
end
defmodule AppSrv do
  def init(arg) do
#    :error_logger.info_report('started!') # ok!
    IO.puts("started!")  # hangup!
    {:ok, []}
  end
  def handle_call({:ping}, _from, state) do
    {:reply, {:pong}, state}
  end
end
---
mix.exs is
---
efmodule App.MixFile do
  use Mix.Project
  def project do
    [
      app: :app,
      version: "0.0.1",
      deps: [
        # Add dependencies here
        # { :foo_bar, "0.1", git: "https://github.com/foo/bar.git" }
      ]
    ]
  end

  # Configuration for the OTP application
  def application do
    [mod: {App, []},
     description: 'minimum app']
  end
end
----
$ mix clean
$ mix iex
Compiled lib/app.ex
Generated app.app
Interactive Elixir (0.7.0.dev) - press Ctrl+C to exit
Erlang R15B01 (erts-5.9.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]

iex(1)> :application.start(:app)

BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
a
--- 
but, in using error_logger.info_report instead of io.format, :application.start(:app) is success!!





2012年4月16日月曜日 5時47分09秒 UTC+9 Carlo Cabanilla:

José Valim

unread,
Aug 16, 2012, 12:58:01 PM8/16/12
to elixir-l...@googlegroups.com
Thanks, I pushed simplest otp app with elixir.


Cheers.

Awesome, thanks. I believe I have pushed a fix to Elixir master that address this.
Could you please let me know how it goes?

k1complete

unread,
Aug 17, 2012, 7:20:59 AM8/17/12
to elixir-l...@googlegroups.com
Thanks.
It reappears when I perform it as follows.

1. clone app from github.
2. $ mix 
3. $ mix idx
4. iex> :application.start(:app)
   !!! hangup !!! stop for ^C and a 

if you want to work normal, replace IO.puts to :error_logger.info_report in lib/app.ex .

Cheers.

2012年8月17日金曜日 1時58分01秒 UTC+9 José Valim:

José Valim

unread,
Aug 17, 2012, 7:33:54 AM8/17/12
to elixir-l...@googlegroups.com
Thanks.
It reappears when I perform it as follows.

1. clone app from github.
2. $ mix 
3. $ mix idx
4. iex> :application.start(:app)
   !!! hangup !!! stop for ^C and a 

I have tried the same on Elixir master and it works fine.

Can you please ensure you are running on master and that you recompiled Elixir with "make clean test" and your project with "mix do clean, iex"?

Thanks!

k1complete

unread,
Aug 17, 2012, 8:46:42 AM8/17/12
to elixir-l...@googlegroups.com
Thanks!!!!!!!!

I confirm fix it problem!!!!!

Great!!! 

2012年8月17日金曜日 20時33分54秒 UTC+9 José Valim:
Reply all
Reply to author
Forward
0 new messages