模块 ringo/subprocess

用于生成进程的模块,连接到它们的输入/输出/ errput并返回它们的响应代码。 它使用由 java.lang.Runtime.getRuntime(). 提供的当前JVM的运行时。 该模块的确切行为与系统高度相关。

Functions

Class Process

Instance Methods

Instance Properties


Process

Process对象可用于控制和获取有关使用createProcess()启动的子进程的信息。


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 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

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 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.stdoutSystem.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 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