process (system, exec, fork...)

Provides access to process manipulation functions. How to work with file descriptors from exec3 is shown in the example#3 and documentation for fs.

Usage:

var process=require("process");

Launching external process:

var process=require("process");

var proc=new process.Process();
proc.system("wget -q -o /tmp/teajs-logo-1.png https://teajs.org/images/teajs-logo-1.png");

Executing bash command with args in array:

var Process = require("process").Process;

var proc = new Process();
var fs = require("fs");

var ECHO = proc.exec3(["bash", "-c", "echo Hello world!"]);

var ECHOOut = new fs.File(ECHO.out);
ECHOOut.open("r");
while (line = ECHOOut.read()) {
    system.stdout.writeLine(line);
}
ECHOOut.close();
var ECHOErr = new fs.File(ECHO.err);
ECHOErr.open("r");
while (line = ECHOErr.read()) {
    system.stdout.writeLine(line);
}
ECHOErr.close();

Executing gzip on file:

var Process = require("process").Process;
var proc = new Process();

var fs=require("fs");

var f1 = new fs.File("unit/tests/texts/very-long-file.txt");
f1.open("r");
var f2 = new fs.File("unit/tests/texts/very-long-file.txt.gz");
f2.open("w");

var line = '';

var zip = proc.exec3(["gzip", "-fc"]);
var zipIn = new fs.File(zip.in);
zipIn.open("w");
while (line = f1.read()) {
    zipIn.write(line);
}
zipIn.close();
var zipOut = new fs.File(zip.out);
zipOut.open("r");
while (line = zipOut.read()) {
    f2.write(line);
}
zipOut.close();
var zipErr = new fs.File(zip.err);
zipErr.open("r");
while (line = zipErr.read()) {
    system.stdout.writeLine(line);
}
zipErr.close();

f2.close();
f1.close();

List of static functions

Name Arguments Returns Description
system String cmd_with_args int Calls C system() function. Returns function call result.
system Array cmd_with_args TODO
fork int Calls C fork() function. Returns function call result.
exec String cmd String Calls C popen() function, reading output and returning it as s result.
exec2 String cmd, String stdin, Object env Object Executes cmd, sending it stdin and returning Object {status,out,err}
exec3 Array cmd_with_args, Object env Object Executes cmd, and returning Object with file descriptors for streams {in,out,err}