close.js 748 B

123456789101112131415161718192021222324
  1. var cmd=process.platform=='win32'?'netstat -ano':'ps aux';
  2. var exec = require('child_process').exec;
  3. var port='9191';
  4. exec(cmd, function(err, stdout, stderr) {
  5. if(err){ return console.log(err); }
  6. stdout.split('\n').filter(function(line){
  7. var p=line.trim().split(/\s+/);
  8. var address=p[1];
  9. if(address!=undefined){
  10. if(address.split(':')[1]==port)
  11. {
  12. exec('taskkill /F /pid '+p[4],function(err, stdout, stderr){
  13. if(err){
  14. return console.log('释放指定端口失败!!');
  15. }
  16. console.log('占用指定端口的程序被成功杀掉!');
  17. });
  18. }
  19. }
  20. });
  21. });