brsolab-process
Wrapper for Nodejs Child process library
Uses the ES6 to make it simple the use of subprocess in nodeJS
This library contains 3 functions: spawn, exec, and escape
spawn is used to create processes.
exec is used to execute commandes via the system interpreter (SH, BATCH, MS-DOS, ...)
escape is used to escape arguments to exec commande
Those two functions use the some options as the original ones of nodejs. See the doc page at: https://nodejs.org/api/child_process.html
spawn
const {spawn} = require('brsolab-process');
var list = await spawn('ls', ['-l', '/home'], {timeout: 500});
exec
const {exec, escape} = require('brsolab-process');
var list = await exec('ls ' + escape(['-l', '/home']), {timeout: 500});
await exec('ls ' + escape(['-l', '/home']) + ' > list.txt', {timeout: 500});
examples
const { spawn, exec } = require('brsolab-process');
const fs = require('fs');
exec('ls .').then( result => console.log(result) ).catch( error => console.error(error) );
(async function(){
result = await spawn('command', [args]);
console.log(result);
await spawn('commande', [args], {stdio : ['pipe', fs.openSync('file.txt'), 'pipe']});
var result = await spawn('cmd', [args], {options}, prcess => {
prcess.send({ foo: 'bar', baz: NaN });
});
})();