mix run executes Elixir code in a Mix project, loading compiled modules and dependencies without opening an interactive shell. Use it for one-off expressions, short-lived tools, or continuously running OTP applications. section 13.1.1 section 2.7.2
Choose the execution mode based on the system’s lifetime:
- Run an expression with `mix run -e`, such as invoking `MyProject.hello()`, then exit. section 13.1.2 section 2.7.2
- Keep an OTP application alive with `mix run --no-halt`; unlike `iex -S mix`, this starts no interactive shell. section 13.1.1
- Use an `.exs` script for a small tool, but move complex or continuously running code into a Mix project and OTP application. section 13.1.2
Start a production-style application
Run `$ mix run --no-halt` to start the BEAM and the OTP application with its dependencies. For background operation, combine Mix with detached Erlang startup and a named node; later connect with a remote shell or stop the node through `System.stop/0`. section 13.1.1
$ mix run --no-halt #1 Starting database worker. Starting database worker. Starting database worker. Starting to-do cache.
Shows the observable startup output produced when `mix run --no-halt` launches application workers. section 13.1.1
