constructor() { super(); _.each([['stdout', process.stdout], ['stderr', process.stderr]], ([name, stream]) => { stream.write = ((stream) => { return (chunk, encoding, fd) => { this.emit(name, { data: chunk, encoding: encoding, fd: fd }); }; })(stream); }); }
https.get( { hostname: 'aip.baidubce.com', path: '/oauth/2.0/token?' + param, agent: false }, function (res) { // 在标准输出中查看运行结果 res.pipe(process.stdout); } );
function clog(string_or_err) //log to console/command prompt { if (!devTools.enableConsoleLog) return; if (string_or_err && string_or_err.hasOwnProperty('stack')) string_or_err = string_or_err.stack; if (!isNull(string_or_err)) process.stdout.write(string_or_err); }
ipcMain.on('osuSongsScan', (event, options) => { // TODO Replace with osu-db-parser module const osuSongsScanProcess = fork(join(__dirname, './processes/osuSongsScan.js'), null, { silent: true }); osuSongsScanProcess.stdout.pipe(process.stdout); osuSongsScanProcess.send(JSON.stringify({ msg: 'start', ...options })); osuSongsScanProcess.on('message', msg => { const { results, status, err } = JSON.parse(msg); if (results) { event.reply('osuSongsScanResults', results); osuSongsScanProcess.kill('SIGTERM'); } if (status) event.reply('osuSongsScanStatus', status); if (err) { event.reply('osuSongsScanError', err); osuSongsScanProcess.kill('SIGTERM'); } }); });