我在对着Nodejs高级教程学习,有一节是向客户端传送子进程输出的例子。
var spawn=require('child_process').spawn;
require('http').createServer(function(req,res){
var child=spawn('tail',['-f','/var/log/system.log']);
child.stdout.pipe(res);
res.on('end',function(){
child.kill();
});
}).listen(4007);
我是在windows系统中安装的babun,然后使用curl命令成功看到结果:
但是在服务器上打开就一直失败...
真心求教。。。强迫症的我一直在研究中.....
__
EDGE11和ff可以。。。不理解 chrome的安全机制吗(我有两个chrome,都无效)
Didn’t you notice that curl never ends? This is not normal.
The main reason is that your child process uses the tail -f command, so that the end time of res will not be triggered, and this request will never end.
You can try using the cat command
You may be using fake chrome. . This is normal for me.
But the only problem is that it keeps requesting data. . It should be that the tail command has not ended.