var spawn = require('child_process').spawn;
require('http').createServer(function(req, res) {
var child = spawn('tail', ['-f', '/var/log/system.log']);//当有一个新的请求出现时,就通过执行 tail -f /var/log/system.log命令启动一个新的进程
child.stdout.pipe(res);//将子进程的输出传入相响应主体中
res.on('end', function() {
child.kill();
});
}).listen(4000);//能生成进程,并传输进程输出的流服务,并根据需要结束子进程
nodejs中向HTTP响应传送进程的输出
最新推荐文章于 2023-12-21 11:00:34 发布