const archive = tar.create(createOpts, fs.readdirSync(configPath)); archive.setEncoding('base64');
}); child.stdout.setEncoding('utf8'); child.stdout.on('data', function ondata(str) { stdout += str; }); child.stderr.setEncoding('utf8'); child.stderr.on('data', function ondata(str) { process.stderr.write(str);
test('build simple addon', function (t) { t.plan(3) // Set the loglevel otherwise the output disappears when run via 'npm test' var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose'] var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) { var logLines = stderr.toString().trim().split(/\r?\n/) var lastLine = logLines[logLines.length - 1] t.strictEqual(err, null) t.strictEqual(lastLine, 'gyp info ok', 'should end in ok') t.strictEqual(runHello().trim(), 'world') }) proc.stdout.setEncoding('utf-8') proc.stderr.setEncoding('utf-8') })
const run = args => new Promise((resolve, reject) => { const c = spawn(process.execPath, [bin].concat(args)) c.on('error', reject) const out = [] const err = [] c.stdout.setEncoding('utf-8') c.stdout.on('data', chunk => out.push(chunk)) c.stderr.setEncoding('utf-8') c.stderr.on('data', chunk => err.push(chunk)) c.on('close', (code, signal) => { resolve({ out: out.join(''), err: err.join(''), code: code, signal: signal }) }) })
test('find python', function (t) { t.plan(4) findPython.test.findPython(null, function (err, found) { t.strictEqual(err, null) var proc = execFile(found, ['-V'], function (err, stdout, stderr) { t.strictEqual(err, null) if (/Python 2/.test(stderr)) { t.strictEqual(stdout, '') t.ok(/Python 2/.test(stderr)) } else { t.ok(/Python 3/.test(stdout)) t.strictEqual(stderr, '') } }) proc.stdout.setEncoding('utf-8') proc.stderr.setEncoding('utf-8') }) })
function launchTarget(...args) { const childProc = spawn(process.execPath, args); return new Promise((resolve, reject) => { const onExit = () => { reject(new Error('Child process exits unexpectly')); }; childProc.on('exit', onExit); childProc.stderr.setEncoding('utf8'); childProc.stderr.on('data', (data) => { const ret = kDebuggerMsgReg.exec(data); childProc.removeListener('exit', onExit); if (ret) { resolve({ childProc, host: ret[1], port: ret[2], }); } }); }); }
unpackToServer(next) { this.logger.debug('Unpacking pack to server.'); const Exec = Process.spawn('tar', ['-xzf', Path.basename(this.archiveLocation), '-C', this.server.path()], { cwd: Path.dirname(this.archiveLocation), stdio: ['ignore', 'ignore', 'pipe'], }); const stderrLines = []; Exec.stderr.setEncoding('utf8'); Exec.stderr.on('data', data => stderrLines.push(data)); Exec.on('error', execErr => { this.logger.error({ location: this.archiveLocation }, execErr); return next(new Error('There was an error while attempting to decompress this file.')); }); Exec.on('exit', (code, signal) => { if (code !== 0) { this.logger.error({ location: this.archiveLocation, code, signal }, `Failed to decompress server pack archive: ${stderrLines.join('\n')}`); } return next(); }); }
test('addon works with renamed host executable', function (t) { // No `fs.copyFileSync` before node8. if (process.version.substr(1).split('.')[0] < 8) { t.skip('skipping test for old node version') t.end() return } t.plan(3) var notNodePath = path.join(os.tmpdir(), 'notnode' + path.extname(process.execPath)) fs.copyFileSync(process.execPath, notNodePath) var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose'] var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) { var logLines = stderr.toString().trim().split(/\r?\n/) var lastLine = logLines[logLines.length - 1] t.strictEqual(err, null) t.strictEqual(lastLine, 'gyp info ok', 'should end in ok') t.strictEqual(runHello(notNodePath).trim(), 'world') fs.unlinkSync(notNodePath) }) proc.stdout.setEncoding('utf-8') proc.stderr.setEncoding('utf-8') })
this._process.stderr.setEncoding('utf-8'); this._process.stdout.setEncoding('utf-8');
this.child = exec(`"${join('node_modules', '.bin', 'mocha')}"`, { cwd }); this.child.stdout.setEncoding('utf8'); this.child.stdout.on('data', this.processData.bind(this)); this.child.stderr.setEncoding('utf8'); this.child.stderr.on('data', this.processData.bind(this)); this.child.on('error', () => { this.finished = Date.now(); });
function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) { return portIsFree(inspectHost, inspectPort) .then(() => { return new Promise((resolve) => { const needDebugBrk = process.version.match(/^v(6|7)\./); const args = (needDebugBrk ? ['--inspect', `--debug-brk=${inspectPort}`] : [`--inspect-brk=${inspectPort}`]) .concat([script], scriptArgs); const child = spawn(process.execPath, args); child.stdout.setEncoding('utf8'); child.stderr.setEncoding('utf8'); child.stdout.on('data', childPrint); child.stderr.on('data', childPrint); let output = ''; function waitForListenHint(text) { output += text; if (/Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\//.test(output)) { const host = RegExp.$1; const port = Number.parseInt(RegExp.$2); child.stderr.removeListener('data', waitForListenHint); resolve([child, port, host]); } } child.stderr.on('data', waitForListenHint); }); }); }
gitResponse.stdout.setEncoding('utf8'); gitResponse.stderr.setEncoding('utf8');
async function executeCommandAndWaitForExitCode(command, args) { let commandExitCode const child = spawn(command, args); child.stdout.setEncoding('utf8'); child.stdout.on('data', (data) => { debugLog(data); }) child.stderr.setEncoding('utf8'); child.stderr.on('data', (data) => { console.error(data); }) child.on('close', (code) => { commandExitCode = code }) child.on('exit', (code) => { commandExitCode = code }) while (commandExitCode === undefined) { debugLog('Waiting for command to finish') await new Promise(resolve => setTimeout(resolve, 500)); } return commandExitCode }
child.stdin.on( 'error', error => errors.stdin = error ) child.stdout.on( 'error', error => errors.stdout = error ) child.stderr.setEncoding( 'utf8' ) child.stderr.on( 'error', error => errors.stderr = error ) child.stderr.on( 'data', data => {
}); child.stdout.setEncoding('utf8'); child.stdout.on('data', function ondata(str) { stdout += str; }); child.stderr.setEncoding('utf8'); child.stderr.on('data', function ondata(str) { process.stderr.write(str);