erlang的脚本执行---escript
1.概述:
作为程序员对于脚本语言应该很熟悉了,脚本语言的优点很多,如快速开发、容易编写、实时开发和执行, 我们常用的脚本有Javascript、shell、python等,我们的erlang语言也有支持脚本运行的工具---escript,它支持在不编译的情况下,直接从命令行运行代码。
2. 示例:
编写了一个使用escript来解析application文件的脚本代码,为了读取vsn字段,如下:
#!/usr/bin/env escript %%% 和其他脚本语言一样,如果脚本未设置,将不可执行 %% -*- erlang -*-
%%! -smp enable -sname app-test -mnesia debug verbose %%% erlang模拟器的参数 -module('app-test').
-mode(compile). %%%脚本语言一般都是解释性语言,而解释执行一般都比编译执行要慢,加上这一句,强制脚本编译。
main(AppFiles) -> %%% escript要求必须有main函数作为入口函数。
ConsistentRstate = lists:foldl(fun
(Rstate, nil) -> Rstate;
(Rstate, Rstate) -> Rstate;
(Rstate, PreviousRstate) ->
io:format(standard_error, "Inconsistent R-States: ~p and ~p~n", [Rstate, PreviousRstate]),
throw(error)
end,
nil,
lists:map(fun
(Filename) ->
{ok, [{application, _Application, Properties}]} = file:consult(Filename),
{vsn, Rstate} = lists:keyfind(vsn, 1, Properties),
Rstate
end,
AppFiles)),
io:format("~s~n", [ConsistentRstate]).
%%% appfile.appSrc 文件,是一个application文件
{application, test,
[
{id, "testId"},
{vsn, "version001"},
{modules, "&modules&"},
{mod, {sysApp, {sysAppCB, []}}},
{description, "this is a test application"},
{maxP, infinity}, % infinity | integer()
{maxT, infinity}, % infinity | integer()
{registered, []}, % [Name1, Name2|...]
{applications, []}, % [Appl1, Appl2|...]
{included_applications, []}, % [Appl1, Appl2|...]
{env, []}
]}.
~/test_tmp> chmod +x app-test.escript
~/test_tmp> ./app-test.escript appfile.appSrc
version001 也可以这样执行.erl .beam .zip ~/test_tmp> cat test.erl
-module(test).
-export([main/]). main([List]) ->
io:format("this is a test module: ~p~n", [List]). ~/test_tmp>
~/test_tmp> escript test.erl testtest
this is a test module: "testtest"
~/test_tmp>
~/test_tmp> erlc test.erl
~/test_tmp> escript test.beam testtest11
this is a test module: "testtest11"
以上是关于escript的简述。如有误,望指正。
erlang的脚本执行---escript的更多相关文章
- erlang虚拟机代码执行原理
转载:http://blog.csdn.NET/mycwq/article/details/45653897 erlang是开源的,很多人都研究过源代码.但是,从erlang代码到c代码,这是个不小 ...
- 第9章 Shell基础(1)_Shell简介和脚本执行方式
1. Shell概述 1.1 Shell简介 (1)Shell是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序,用户可以用Shell来启动.挂起.停止甚至是编 ...
- MonoBehaviour Lifecycle(生命周期/脚本执行顺序)
脚本执行顺序 前言 搭建一个示例来验证Unity脚本的执行顺序,大概测试以下部分: 物理方面(Physics) 渲染(Scene rendering) 输入事件(InputEvent) 流程图 Uni ...
- Shell文件权限和脚本执行
一.预备知识 1.shell的作用 2.常识 (1)Tab键自动补全 使用Terminal时,输入命令的前几个字母,敲tab会自动补全命令或文件名.目录等. 好处:操作速度更快:不容易出错: ...
- python脚本执行Scapy出现IPv6警告WARNING解决办法
安装完scapy,写了脚本执行后执行: WARNING: No route found for IPv6 destination :: (no default route?) 原因是用 from sc ...
- Linux脚本执行过程重定向
Linux脚本执行过程重定向 一.bash调试脚本,并将执行过程重定向到指定文件 bash –x shell.sh 2>&1 | tee shell.log
- PowerDesigner16.5 生成SQL脚本执行出错:collate chinese_prc_ci_as
PowerDesigner16.5 生成SQL脚本执行出错, collate chinese_prc_ci_as 点DataBase-edit current dbms —— 左边Script - O ...
- sh脚本执行Java程序
1.不引用Jar包或者资源文件夹 最简单的程序Hello World. 首先创建Hello.java public class Hello { public static void main(Stri ...
- crontab 中 python(cx_Oracle)脚本执行时需要用户环境变量,怎么办??
import cx_Oracle Traceback (most recent call last): File "", line 1, in ? ImportError: lib ...
随机推荐
- Install and run DB Query Analyzer 6.04 on Microsoft Windows 10
Install and run DB Query Analyzer 6.04 on Microsoft Windows 10 DB Query Analyzer is presented ...
- Android实现自定义的相机
使用系统相机 android中使用系统相机是很方便的,单这仅仅是简单的使用而已,并不能获得什么特殊的效果. 要想让应用有相机的action,咱们就必须在清单文件中做一些声明,好让系统知道,如下 < ...
- Linux IPC实践(3) --具名FIFO
FIFO具名/命名管道 (匿名)管道应用的一个限制就是只能在具有共同祖先(具有亲缘关系)的进程间通信. 如果我们想在不相关的进程之间交换数据,可以使用FIFO文件来做这项工作,它经常被称为命名管道;命 ...
- 【leetcode82】Linked List Cycle
题目描述: 判断有序list是不是环 要求: 时间复杂度o(n) 原文描述: Given a linked list, determine if it has a cycle in it. Follo ...
- 面向对象编程(OOP)的五大特征-java学习之旅(1)
这是Alan Kay关于第一个成功的面向对象语言SmallTalk的总结: 1.所有的东西都是对象.可将对象想象成一种新型的变量:它保存着数据,但是可要求它对自身进行操作,理论上讲,可从要解决的问题身 ...
- 08_Android中的SimpleAdapter的使用
1 目的界面 2.编写Android清单文件 <?xml version="1.0" encoding="utf-8"?> <manif ...
- 05_学生管理系统,xml读写,布局的综合应用
最终要做的项目目标: 2.编写Android清单文件AndroidManifest.xml <?xml version="1.0" encoding="utf ...
- 恭喜发财! -- 手把手教你仿造一个qq下拉抢红包 Android自定义view
猴年猴赛雷啊各位,今天没吃药我感觉自己萌萌哒! qq和微信和支付宝红包大战,不知道各位的战绩是多少嘞? 反正我qq抢到的都是气泡.因为太不爽,所以自己写一个下拉抢红包自己玩(自己跟自己玩). 先来看效 ...
- 再回首UML之上篇
UML,统一建模语言,是一种用来对真实世界物体进行建模的标准标记,这个建模的过程是开发面向对象设计方法的第一步,UML不是一种方法学,不需要任何正式的工作产品. UML提供多种类型的模型描述图,当在某 ...
- 03_TortoiseGit冲突和补丁演示,补丁冲突
1 下载TortoiseGit,下载地址: http://tortoisegit.soft32.com/free-download/ 2 创建一个GIT仓库 3 创建克隆,创建两个用于克隆的仓库 ...