function doTask(date) { const env = {DATE: date} console.log('DATE=', date) const p1 = exec('node reduce.js', {env: env}, (err) => { assert.ifError(err) const p2 = exec('indexer -c sphinx.conf hash_delta --rotate', {env: env}, (err) => { assert.ifError(err) const p3 = exec('indexer -c sphinx.conf --merge hash hash_delta --rotate', (err) => { assert.ifError(err) console.log(new Date(), date, 'task done') }) p3.stdout.pipe(process.stdout) }) p2.stdout.pipe(process.stdout) }) p1.stdout.pipe(process.stdout) }
cp.stdout.on('data', function (data) { console.log(data + ''); })
function exec (cmd, onFinish, onData) { console.log('$ ' + cmd); if (onFinish instanceof Function || onFinish === null) { const result = shelljs.exec(cmd, { async: true, silent: !verbose }, onFinish); if (onData instanceof Function) { result.stdout.on('data', onData); } } else { return shelljs.exec(cmd, { silent: !verbose }); } }
gulp.task('dev', function(cb) { livereload.listen({port: 35729}); gulp.watch('src/*', function(event) { gulp.src('src/*').pipe(livereload()); }); var isWin = /^win/.test(process.platform); const electronProcess = require('child_process') .exec((isWin ? 'sh' : 'node') + ' ./node_modules/.bin/electron ./src/', { cwd: __dirname, env: Object.assign( {}, process.env, { NODE_ENV: 'dev' }) }, cb); electronProcess.stdout.on('data', function(data) { console.log(data); }); electronProcess.stderr.on('data', function (data) { console.log('stderr: ' + data.toString()); }); });
exec(command: string, quiet: boolean, options?: any) { return new Promise((resolve, reject) => { try { const child = childProcess.exec( command, Object.assign({ encoding: 'utf8', wraning: false, maxBuffer: Infinity }, options), (error, stdout, stderr) => { if (error) { console.warn( 'Command run error, please check if there has the same issue here: https://github.com/weexteam/weex-toolkit/issues/337', ) reject(error) } else { resolve() } }, ) if (!quiet) { child.stdout.pipe(process.stdout) } child.stderr.pipe(process.stderr) } catch (e) { console.error('execute command failed :', command) reject(e) } }) }
nodemon.stdout.on('data', function (data) { console.log(data.toString()); });
phantom.stdout.on('data', function(data) { stdout += data; });