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); }
// Works on Mac. // TODO: Linux - Ubuntu et al. function get_arp_table(callback){ var arp = spawn('arp', ['-a']); var arp_str = ""; arp.stdout.setEncoding('utf8'); arp.stdout.on('data', function(data){ arp_str = data; }); arp.on('close', function(x){ callback(null, parse_arp_table(arp_str)); //arp.kill(); }); }
child.on("exit", (code, signal) => { console.log(`child exited with code: ${code}, signal: ${signal}`) })
const runElmFormat = code => { const bin = '/src/elm/elm-format' return new Promise((resolve, reject) => { let output = [] const child = spawn(bin, ['--stdin']) child.stdout.on('data', c => output.push(c.toString())) child.stdin.write(code) child.stdin.end() child.on('close', exitCode => { return resolve(exitCode ? code : output.join('')) }) }) }
const backupMongo = function (mongoUrl, path) { console.log('Backing up mongodb', mongoUrl, 'to', path); let uri = mongoUri.parse(mongoUrl); let parameters = dumpParameters(uri, path); const command = 'mongodump'; let future = new Future(); let dumpProcess = spawn(command, parameters); dumpProcess.on('error', console.log); dumpProcess.on('close', code => { console.log('mongodump ended with exit code', code); future.return(); }); return future.wait(); }
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.stdout.on('data', (data) => { str += data.toString(); if (str.includes('\n')) { this.process.stderr.on('data', (data) => { this.emit('stderr', `STDERR: ${data.toString().replace(/\n$/, '')}`); //TODO red color }); this.process.on('close', (code) => { this.emit('exit', code); }); this.process.on('error', ({code, message}) => { if (code === 'ENOENT') { this.emit('error', `Failed to run subprocess, try to run command with out UTop: "${this.props.fullCommand}"`);
ideviceprovision.stdout.on('data', (chunk) => { file.write(chunk); }); ideviceprovision.stdout.on('end', () => { file.end(); logger.info('Installed provisioning profiles saved'); }); ideviceprovision.on('close', function (code) { if (code !== 0) { callback(new Error('ideviceprovision returned error code ' + code));
idevicecrashreport.stdout.on('data', (chunk) => { file.write(chunk); }); idevicecrashreport.stdout.on('end', () => { file.end(); logger.info('Crash reports and log saved'); }); idevicecrashreport.on('close', function (code) { if (code !== 0) { return callback(new Error('idevicecrashreport returned error code ' + code));
function getInstalledApps (udid, wd, callback) { const filename = 'installed-apps.xml'; const file = fs.createWriteStream(wd + '/artifacts/' + filename); // call ideviceinstaller binary const ideviceinstaller = childProcess.spawn('ideviceinstaller', ['--list-apps', '-o', 'list_all', '-o', 'xml']); // on data events, write chunks to file ideviceinstaller.stdout.on('data', (chunk) => { file.write(chunk); }); // after Stream ends, close the file, inform user of saved file ideviceinstaller.stdout.on('end', () => { file.end(); logger.info('iOS Device installed apps saved'); callback(null, ideviceinstaller); }); ideviceinstaller.on('close', function (code) { if (code !== 0) { callback(new Error('ideviceinstaller returned error code ' + code)); } }); }
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); }); }