Mix v1.6.0 mix run View Source

Starts and runs the current application.

mix run can be used to start the current application dependencies ant the application itself. For long running systems, this is typically done with the --no-halt option:

mix run --no-halt

If there is a desire to execute a script within the current application or configure the application via command line flags, it is possible to do so by passing a script file or an eval expression to the command:

mix run my_app_script.exs arg1 arg2 arg3
mix run -e "MyApp.start" -- arg1 arg2 arg3

In both cases, the command line flags are available under System.argv/0.

Before running any command, Mix will compile and start the current application. If for some reason the application needs to be configured before it is started, the --no-start flag can be used and you are then responsible for starting all applications by using functions such as Application.ensure_all_started/1. For more information about the application life-cycle and dynamically configuring applications, see the Application module.

If you need to pass options to the Elixir executable at the same time you use mix run, it can be done as follows:

elixir --sname hello -S mix run --no-halt

Command line options

  • --config, -c - loads the given configuration file
  • --eval, -e - evaluate the given code
  • --require, -r - requires pattern before running the command
  • --parallel, -p - makes all requires parallel
  • --preload-modules - preloads all modules defined in applications
  • --no-compile - does not compile even if files require compilation
  • --no-deps-check - does not check dependencies
  • --no-archives-check - does not check archives
  • --no-halt - does not halt the system after running the command
  • --no-mix-exs - allows the command to run even if there is no mix.exs
  • --no-start - does not start applications after compilation
  • --no-elixir-version-check - does not check the Elixir version from mix.exs

Link to this section Summary

Functions

A task needs to implement run which receives a list of command line args

Link to this section Functions

A task needs to implement run which receives a list of command line args.

Callback implementation for Mix.Task.run/1.