我在 MacOS 和 linux 中使用 node.js v0.10.12 遇到了这个错误,这段代码在 windows 7 中运行良好。唯一的区别是在 windows 7 上我有管理员 id,在 MacOSX 和 linux 上,我不是 root,只是计划用户。
我们需要 root 才能使用 child_process 吗?关于为什么它在某些操作系统而不是全部操作系统上失败的任何线索?非常感谢,
这是代码:
var spawn = require('child_process').spawn;
try {
var child = spawn('node', ['plusone.js']);
//call every minute
setInterval(function() {
//
var number = Math.floor(Math.random() * 10000);
child.stdin.write(number +'\n');
child.stdout.once('data', function(data) {
console.log('child replied to '+ number +' with ' +data);
});
},1500);
child.stderr.on('data', function(data) {
process.stdout.write(data);
});
} catch (e)
{
console.log("entering catch block");
console.log(e);
}