【www.bbyears.com--js教程】
word">var
spawn = require(
'child_process'
).spawn;
require(
'http'
).createServer(
word">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);
//能生成进程,并传输进程输出的流服务,并根据需要结束子进程