node.js
var sys = require('sys')
filename = process.ARGV[2],
spawn = require('child_process').spawn;
if (!filename)
return sys.puts("Usage: node watcher.js filename");
// Look at http://nodejs.org/api.html#_child_processes for detail.
var tail = spawn("tail", ["-f", filename]);
sys.puts("start tailing");
tail.stdout.addListener("data", function (data) {
sys.puts(data);
});
// From nodejs.org/jsconf.pdf slide 56
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
tail.stdout.addListener("data", function (data) {
response.write(data);
});
//response.end('Hello World\n');
}).listen(8124);
root@core:~# echo 'line 10' >> foo
沒有留言:
張貼留言