function run(title) { console.log(`Run child process: ${title} ${scriptPath}`); const childProcess = spawn('node', [scriptPath]); console.log(`Child process ${title} pid: ${childProcess.pid}`); childProcess.stdout.on('data', (data) => process.stdout.write(`Process ${title}: ${data.toString()}`)); childProcess.stderr.on('data', (data) => process.stdout.write(`Process ${title}: ${data.toString()}`)); childProcess.on('error', ({message}) => console.log(`Process ${title} ERROR: ${message}`)); childProcess.on('close', (code) => console.log(`Process ${title} exited: ${code}`)); childProcesses.push(childProcess); }
function launch(id) { let prc = spawn('node', ['peer.js', id]); let stderr = ''; prc.stdout.setEncoding('utf8'); prc.stdout.on('data', function (data) { var str = data.toString() var lines = str.split(/(\r?\n)/g); console.log(lines.join("").trim()); }); prc.stderr.on('data', function (buf) { stderr += buf; console.log('Err: '+stderr); }); prc.on('close', function (code) { console.log('Peer ' + id + ' exited with code ' + code); console.log('stderr ' + stderr); }); }
describe("end-to-end", function() { this.timeout(10000); it("standart flow", function(done) { const questions = ["GitHub username", "GitHub password", "access token", "owner of the repositories", "copy labels", "add labels", "predefined labels", "select the issues", "label name", "select the color"]; const answers = [process.env.USER_NAME, process.env.USER_PASS, "n", process.env.USER_NAME, "n", "a", "n", "a", "test-label", "FFFFFF"].map((a) => a + "\n"); let currentStep = 0; const cli = spawn("node", ["index.js"]); cli.stdout.setEncoding("utf8"); cli.stdout.on("data", function(data) { if(data.indexOf(questions[currentStep]) > -1) { cli.stdin.write(answers[currentStep]); currentStep++; if(currentStep === questions.length) { return done(); } } }); cli.stderr.on("data", done); cli.on("close", done); }); });
/** * Wrapper around `child_process.spawn()` that creates a child node process to execute the given * process path, returning a promise that can be awaited. * * @param {string} processPath * @param {string[]} args * @param {object} opts * @returns */ const _executeNode = (processPath, args = [], opts = {}) => { const { env = null } = opts; const childProcess = _createNodeProcess(processPath, args, env); childProcess.stdin.setEncoding("utf-8"); return new Promise((resolve, reject) => { childProcess.stderr.once("data", (err) => { reject(err.toString()); }); childProcess.on("error", reject); childProcess.stdout.pipe( concat((result) => { resolve(result.toString()); }) ); }); }
this.process.stderr.on('data', (data) => { this.emit('stderr', `STDERR: ${data.toString().replace(/\n$/, '')}`); //TODO red color });
let ffmpegExe = child_process.spawn('ffmpeg', params); ffmpegExe.stderr.on('error', (data) => { logger.log('info', 'Audio file conversion faild', {error : data, file: fileName}); });