[脚本语言JavaScript]Ringo JS-模块 ringo/subprocess

RingoJS是一个服务器端的JavaScript平台,利用Mozilla Rhino引擎执行脚本,适用于命令行工具、Web应用及GUI应用开发。它采用CommonJS模块系统,提供丰富的API和模块,如ringo/subprocess模块,用于生成子进程并处理输入/输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

Streaminput

output stream to connect to the process's input stream

Streamoutput

input stream to connect to the process's output stream

Streamerrput

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

Stringcommand

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 dir string property specifying the directory to run the process in and a env object property specifying additional environment variable mappings.

Returns

String

the standard output of the command


createProcess (args)

产生新进程的低级函数。该函数接受一个包含以下属性的对象参数,其中除command之外的所有属性都是可选的:

  • command 包含要执行的命令的字符串或字符串数组。哪个字符串列表表示有效的操作系统命令是依赖于系统的。
  • dir 运行该进程的目录
  • env 替代的环境变量。如果为null,则进程继承当前进程的环境。
  • binary 一个使用原始二进制流代替文本流的布尔标志
  • encoding 用于文本流的字符编码

Parameters

Objectargs

an object containing the process command and options.

Returns

Process

a Process object

See

Process


status (command, [arguments...], [options])

默默地执行给定的命令并返回退出状态。

Parameters

Stringcommand

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 dir string property specifying the directory to run the process in and a env object property specifying additional environment variable mappings.

Returns

Number

exit status


system (command, [arguments...], [options])

执行附加到JVM进程的输出和错误流 System.stdout 和 System.stderr, 的给定命令,并返回退出状态。

Parameters

Stringcommand

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 dir string property specifying the directory to run the process in and a env object property specifying additional environment variable mappings.

Returns

Number

exit status

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值