Ringo 是一个 JavaScript 平台
ECMA JavaScript 规范将该语言描述为面向对象的编程语言,用于在主机环境中执行计算和处理计算对象。每个用 JavaScript 编写的应用程序都需要一个主机环境,它提供特定于环境的对象和 API 来执行 I / O。 Ringo 为 JavaScript 提供了这样一个环境,并附带一组模块以使应用程序开发更容易。由于其作为通用编程语言的特性,JavaScript 可以用来解决各种各样的问题,而 Ringo 可以帮助您这么做。利用 Ringo,编写命令行工具,复杂的 Web 应用程序甚至基于 Java UI 技术的 GUI 应用程序都很容易。
脚本语言如 JavaScript 需要一个引擎来解释和执行程序。 Ringo 没有自己的引擎。相反,它使用 Mozilla Rhino,一种 Java 中的 JavaScript 实现。犀牛的最初发展始于 Netscape 时代,并一直持续到现在。基本思想是将 JavaScript 程序编译为 Java 字节码,Java 字节码可以由 Java 虚拟机(JVM)执行。犀牛还提供了对 Java 标准类库和其他每个 Java 类的轻松访问。这使得将现有的 Java 库集成到新的 JavaScript 应用程序变得很容易。例如:Ringo 不是编写自己的 I / O 系统,而是使用现有的 Java I / O 类,并将它们封装起来以提供从 JavaScript 更容易的访问。
Ringo 在服务器或专用机器上执行 JavaScript,而不是在 Web 浏览器上下文中执行。如果您已经从基于 HTML 的应用程序中了解 JavaScript,则这是主要区别。没有什么像一个窗口对象,你没有一个 DOM 来操纵 HTML 对象。尽管如此,很多事情会像你从浏览器中知道的那样。您可以使用 console.log() 调试到控制台,但也有专用的日志记录模块可用于更复杂的日志记录。
Ringo 最大的优势之一就是模块系统。 Ringo 并没有自己构建代码,而是拥有一个易于使用的模块系统。它基于 CommonJS 模块,这是用于保持代码可互换的服务器端 JavaScript 环境的规范。如果您了解 Node.js 的模块,您还知道如何在 Ringo 中编写模块。一个模块封装了 JavaScript 方法和变量,并将它们与其他模块隔离。
模块 ringo/subprocess
用于生成进程的模块,连接到它们的输入/输出/ errput并返回它们的响应代码。 它使用由 java.lang.Runtime.getRuntime(). 提供的当前JVM的运行时。 该模块的确切行为与系统高度相关。
Functions
- command (command, [arguments...], [options])
- createProcess (args)
- status (command, [arguments...], [options])
- system (command, [arguments...], [options])
Class Process
Instance Methods
Instance Properties
Process
Process对象可用于控制和获取有关使用createProcess()启动的子进程的信息。
See
http://docs.oracle.com/javase/8/docs/api/java/lang/Process.html
Process.prototype. connect (input, output, errput)
将进程的流连接到参数流,并启动线程以异步复制数据。
Parameters
Stream | input | output stream to connect to the process's input stream |
Stream | output | input stream to connect to the process's output stream |
Stream | errput | input stream to connect to the process's error stream |
Process.prototype. kill ()
杀死子进程。
Process.prototype. stderr
该进程的错误流。
Process.prototype. stdin
该进程的输入流。
Process.prototype. stdout
该进程的输出流。
Process.prototype. wait ()
等待进程终止并返回其退出状态。
command (command, [arguments...], [options])
执行给定的命令并返回标准输出。如果退出状态不为零,则会引发错误。例子:
var {command} = require("ringo/subprocess");
// get PATH environment variable on Unix-like systems
var path = command("/bin/bash", "-c", "echo $PATH");
// a simple ping
var result = command("ping", "-c 1", "ringojs.org");
Parameters
String | command | command to call in the runtime environment |
String | [arguments...] | optional arguments as single or multiple string parameters. Each argument is analogous to a quoted argument on the command line. |
Object | [options] | options object. This may contain a |
Returns
String | the standard output of the command |
createProcess (args)
产生新进程的低级函数。该函数接受一个包含以下属性的对象参数,其中除command之外的所有属性都是可选的:
command
包含要执行的命令的字符串或字符串数组。哪个字符串列表表示有效的操作系统命令是依赖于系统的。dir
运行该进程的目录env
替代的环境变量。如果为null,则进程继承当前进程的环境。binary
一个使用原始二进制流代替文本流的布尔标志encoding
用于文本流的字符编码
Parameters
Object | args | an object containing the process command and options. |
Returns
Process | a Process object |
See
status (command, [arguments...], [options])
默默地执行给定的命令并返回退出状态。
Parameters
String | command | command to call in the runtime environment |
String | [arguments...] | optional arguments as single or multiple string parameters. Each argument is analogous to a quoted argument on the command line. |
Object | [options] | options object. This may contain a |
Returns
Number | exit status |
system (command, [arguments...], [options])
执行附加到JVM进程的输出和错误流 System.stdout
和 System.stderr
, 的给定命令,并返回退出状态。
Parameters
String | command | command to call in the runtime environment |
String | [arguments...] | optional arguments as single or multiple string parameters. Each argument is analogous to a quoted argument on the command line. |
Object | [options] | options object. This may contain a |
Returns
Number | exit status |