有没有办法在erlang shell中运行带有指令的文件?

问题描述

| 我在运行erl shell的当前目录中有一个文件.erlang,它编译了一些模块。 有没有办法从Erlang Shell重新运行此文件。 我运行erl,得到外壳程序1>,然后从那里运行,就像run_file(\“。erlang \”)一样,该文件在当前外壳程序中执行指令并加载env。 该文件看起来像
compile:file(file1). 
compile:file(file2).
compile:file(file3).
...
    

解决方法

您正在寻找
file:eval/1
。 给定带有该内容的
.erlang
io:format(\"Hello world!~n\").
你得到:
Eshell V5.7.5  (abort with ^G)
1> file:eval(\".erlang\").
Hello,world!
ok
    ,您可能需要研究escript。