Javascript process.stdout不';“没有功能”;clearLine“;在生育过程中
在“Main.js”中,我使用spawn创建了一个子进程。我想从“work.js”中获取数据,但它显示了错误Javascript process.stdout不';“没有功能”;clearLine“;在生育过程中,javascript,node.js,Javascript,Node.js,在“Main.js”中,我使用spawn创建了一个子进程。我想从“work.js”中获取数据,但它显示了错误 TypeError: out.clearLine is not a function 如果在终端中使用node work.js,则工作正常 似乎process.stdout在childProcess中没有函数“clearLine” main.js var spawn = require('child_process').spawn; var child = spawn('node',[
TypeError: out.clearLine is not a function
如果在终端中使用node work.js
,则工作正常
似乎process.stdout在childProcess中没有函数“clearLine”
main.js
var spawn = require('child_process').spawn;
var child = spawn('node',['work.js']);
child.stdout.on('data', function (data) {
console.log('data:',data.toString());
})
child.stderr.on('data', function (data) {
console.log("stderr:", data.toString());
});
work.js
var out = process.stdout;
var idx = 0;
var id = setInterval(()=>{
idx++;
out.clearLine();
out.cursorTo(0);
out.write('workTime:' + idx);
if(idx>3){
clearInterval(id);
console.log();
console.log('end')
}
},100)
这只是一个演示,我无法更改work.js。如何修复main.js中的问题,谢谢请参阅:
var readline = require('readline');
function writeWaitingPercent(p) {
//readline.clearLine(process.stdout);
readline.cursorTo(process.stdout, 0);
process.stdout.write(`waiting ... ${p}%`);
}