erlang - 启动脚本
为了启动我的程序,我执行下一个序列:
$ erl
> c(module1).
> c(module2).
> c(modulen).
modulen:start().
是否有可能创建允许我启动我的程序的脚本?
To start my program I do the next sequence:
$ erl
> c(module1).
> c(module2).
> c(modulen).
modulen:start().
Is there any possibility to create script that allow me to launch my program ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用加载器脚本来以 OTP 方式启动应用程序:
您可以通过 shell 脚本启动该脚本。如果您计划构建在操作系统启动时运行的守护进程,请小心使用
escript
,因为它们很棘手。当然,您需要
XYZ.app
文件(只是一个示例):...并且所有
.erl
文件必须已编译。注意,如果您打算分发应用程序(例如 Debian 存储库等),您可能应该考虑使用
make
文件来编译和安装您的应用程序。最后一点:您也可以使用
boot
文件(最终的 OTP 方式),但我发现这些文件非常有限制:引导文件将您的应用程序与特定版本发布联系起来Erlang(以及其他相关应用程序)的。您的应用程序可能能够在各种 Erlang 版本中运行,但您需要为您打算发布的每个“平台版本”有一个单独的构建/发布过程。You could use a loader script that takes care of starting your application in an OTP fashion:
You launch that script through a shell script. Beware of using
escript
if you plan on building daemons running at the OS boot time as they are tricky.Of course you need your
XYZ.app
file (just an example):... and all your
.erl
files must have been compiled.Note that if you intend to distribute your application (e.g. Debian repository etc), you probably should consider having a
make
file to compile and install your app.As a final note: you could also go with a
boot
file (the ultimate OTP way) but I find those very constraining: a boot file ties your application to specific version release of Erlang (and other dependent applications). Your application might be able to run in various Erlang releases but you will need to have a separate build/release process for each "platform release" you intend to ship for.您可以使用 erlc 编译模块
您还可以创建一个脚本来运行您的程序
然后在控制台中:
You can compile the modules with
erlc
You can also create a script to run you program
Then in the console:
两种方法
预编译代码的
或者使用 escript
escript 是 Erlang 的脚本接口
Two ways
precompile your code
Or use escript
escript is a scripting interface to Erlang
您可以直接使用
erl -make
,因为它假定所有*.erl
文件都应编译为*.beam
,如果它们是,则跳过它自上次编译以来未曾更改。查看 make 模块,了解可以放入Emakefile 中的内容
改变某些行为。使用简单的
Makefile
来调用此编译策略也为其他用户提供了熟悉的构建过程。jldupont 建议的引导启动功能是启动开发环境的好方法。在某种程度上,它甚至足以在生产中使用。
下一步是使用完整的 OTP (
*.rel
) 发布文件并生成启动脚本,该脚本按照*.app
指定彼此依赖关系的顺序启动所有应用程序。You can use
erl -make
directly, as it assumes all*.erl
files should be compiled to*.beam
, and skip it if they haven't been changed since last compile. Check out the make module for what you can put in yourEmakefile
to change certain behavior.Using plain
Makefile
to invoke this compile strategy also gives other users a familiar build-procedure.Having a bootstrap start function as jldupont suggests is a nice way to start up your development environment. It is even sufficiently fine for using in production to some point.
The next step is to use full OTP (
*.rel
) release files and generate boot scripts that starts all the applications in the order the*.app
specify dependencies on each other.在主目录中,创建文件
.erlang
在该文件中写入
,如果您需要添加(在 .erlang 内部):
当您运行 erl (在 shell 中)时,.erlang 的内容(前提是该文件位于主目录中) )将在(您启动的解释器-erlang-VM)启动时执行。
您可以在其他(某个“当前”)目录中创建 .erlang 文件,然后,如果您在该目录中运行 erl (erlang 解释器),则另一个 .erlang 将覆盖主目录(该目录的主目录)中该 .erlang 的内容就像 /home/your-user-name/.erlang )。
最好在 .erlang 内部编写一些提醒,例如
(不要忘记该代码,否则这些代码将默默执行!)
(此外,对于这种情况,您可以检查例如 module1 确实在之后编译和加载开始,这样或类似的方式:
答案应该是这样的:
[{module1,"/home/您的用户名/(您的代码路径)/module1.beam"}]
)
In the home directory, create file
.erlang
in that file write
then, if you need add (inside .erlang):
When you run erl (in the shell), the content of the .erlang (provided this file is in the home dir) will be executed at start (of the interpreter-erlang-VM you launch).
You can create .erlang file in some other (some 'current') directory, then, if you run erl (erlang interpreter) in that directory, that another .erlang will override the content of that .erlang in the home dir (of that which is like /home/your-user-name/.erlang ).
It is good idea to write inside of .erlang some reminder, like
(as not to forget about that code which otherwise will be executed silently !)
(also, you can check, for this case, that e.g. module1 is indeed compiled and loaded after start, this or some similar way:
the answer should be like:
[{module1,"/home/your-user-name/(path-to-your-code)/module1.beam"}]
)
看看 Sinan 和 Faxien:http://www.erlware.org
Check out Sinan and Faxien: http://www.erlware.org