For executing shell comand you can use Loki. You can find functions for shell execution execute/1
.
And example how I used in Mix.Task for executing other mix tasks:
defmodule Mix.Tasks.Sesamex.Gen.Auth do
use Mix.Task
import Loki.Cmd
import Loki.Shell
@spec run(List.t) :: none()
def run([singular, plural]) do
execute("mix sesamex.gen.model #{singular} #{plural}")
execute("mix sesamex.gen.controllers #{singular}")
execute("mix sesamex.gen.views #{singular}")
execute("mix sesamex.gen.templates #{singular}")
execute("mix sesamex.gen.routes #{singular}")
# ...
end
end
Or just look how it execute command:
@spec execute(String.t, list(Keyword.t)) :: {Collectable.t, exit_status :: non_neg_integer}
def execute(string, opts) when is_bitstring(string) and is_list(opts) do
[command | args] = String.split(string)
say IO.ANSI.format [:green, " * execute ", :reset, string]
System.cmd(command, args, env: opts)
end
Hope it help you.