我想运行两个elixir脚本,first.exs和second.exs.我想第二个也先跑.什么是一个很好的方式来运行它?
例如,代码可能如下所示:
first.exs
IO.puts "first"
Run Code Online (Sandbox Code Playgroud)
second.exs
IO.puts "second"
System.cmd("mix run first.exs")
Run Code Online (Sandbox Code Playgroud)
并输出这样的东西:
mix run first.exs
first
mix run second
first
second
Run Code Online (Sandbox Code Playgroud)
我想避免使用System.cmd,Mix尽可能使用该模块
你可以使用Code.eval_file:
Code.eval_file "first.exs"
Run Code Online (Sandbox Code Playgroud)
$ cat first.exs
IO.puts "first"
$ cat second.exs
IO.puts "second"
Code.eval_file "first.exs"
$ mix run second.exs
second
first
Run Code Online (Sandbox Code Playgroud)