Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var http = require('http');
  2. var spawn = require('child_process').spawn;
  3.  
  4. http.createServer(onRequest).listen(4000);
  5.  
  6. function onRequest(request, response)
  7. {  
  8.     response.writeHead(200, {'Content-Type' : 'text/plain'});
  9.  
  10.     var tail_child = spawn('tail', ['-f', '/var/log/system.log']);
  11.  
  12.     request.connection.on('end', onEnd);
  13.     tail_child.stdout.on('data', onLoadData);
  14.  
  15.     function onEnd()
  16.     {  
  17.         tail_child.kill();
  18.     }
  19.  
  20.     function onLoadData(data)
  21.     {  
  22.         console.log(data.toString());
  23.         response.write(data);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement