Search code examples
batch-filecmdelixirelixir-iex

How can I run batch in a shell?


I want to have a batch file that opens the command prompt, launches the iex shell within it and then starts my elixir program. The issue I'm having is that as soon as I invoke iex -S mix, which compiles the code and opens the elixir shell, then I am unable to write more commands into it.

:: Start iex and compile with mix
iex -S mix

:: Start elevators 
Elevator.Supervisor.start

pause 

enter image description here

The last part Elevator.Supervisor.start never runs, for some reason. I guess this is because I opened a shell within the command prompt. Is there a way to feed commands into the iex?


Solution

  • TL;DR use .iex.exs file which is loaded by iex upon start.


    • Create a file named .iex.exs in the project directory root with the content you want to be run:
        Elevator.Supervisor.start()
    
    • remove any reference to code (which is now located in .iex.exs) from your .bat file
    • run .bat file
    • enjoy.