Giter VIP home page Giter VIP logo

Comments (3)

yibn2008 avatar yibn2008 commented on June 10, 2024

请给一下具体的报错信息

from find-process.

ureuerae avatar ureuerae commented on June 10, 2024

测试过程:
程序路径 :“‪D:\中文文件夹\SSTap1.9.7\SStap197.exe”,启动后监听端口 “25379” ,已通过任务管理器知道程序运行pid为4484。

port_check.js 内容如下:

const find = require('find-process');
function checkp(port){
	find('port', port)
	  .then(function (list) {
		  console.log(list);
		if (!list.length) {
		  console.log(`port ${port} is free now`);
		} else {
		  console.log(`%s is listening port ${port}`, list[0].name);
		}
	}, function (err) {
      console.log(err.stack || err);
    })	
}
function checkpid(pid){
	find('pid', pid)
	  .then(function (list) {
		console.log(list);
		
		if (!list.length) {
		  console.log(`pid ${pid} is free now`);
		} else {
		  console.log(`%s is listening pid ${pid}`, list[0].name);
		}

	  }, function (err) {
		console.log(err.stack || err);
	})
}
checkp(25379);
checkpid(4484);

以管理员身份运行power shell结果如下:

PS D:\port_check> netstat -ano |findstr 25379
  TCP    127.0.0.1:25379        0.0.0.0:0              LISTENING       4484
  TCP    127.0.0.1:25379        127.0.0.1:64020        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64022        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64023        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64026        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64027        TIME_WAIT       0
  TCP    127.0.0.1:64021        127.0.0.1:25379        TIME_WAIT       0
PS D:\port_check> node portcheck.js
[]
pid 4484 is free now
[]
port 25379 is free now
PS D:\port_check>

没有检查到端口占用。

反之,在非中文路径下可以检查到占用程序:

程序路径 :“‪D:\feizhongwen\SSTap1.9.7\SStap197.exe”,启动后监听端口 “25379” ,已通过任务管理器知道程序运行pid为5792。

PS D:\port_check> netstat -ano |findstr 25379
  TCP    127.0.0.1:25379        0.0.0.0:0              LISTENING       5792
  TCP    127.0.0.1:25379        127.0.0.1:64093        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64094        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64095        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64096        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64097        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64098        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64101        ESTABLISHED     5792
  TCP    127.0.0.1:25379        127.0.0.1:64104        TIME_WAIT       0
  TCP    127.0.0.1:25379        127.0.0.1:64107        TIME_WAIT       0
  TCP    127.0.0.1:64101        127.0.0.1:25379        ESTABLISHED     8880
  TCP    127.0.0.1:64104        127.0.0.1:25379        TIME_WAIT       0
  TCP    127.0.0.1:64107        127.0.0.1:25379        TIME_WAIT       0
PS D:\port_check> node portcheck.js
[
  {
    pid: 5792,
    ppid: 8288,
    bin: 'D:\\feizhongwen\\SSTap1.9.7\\SStap197.exe',
    name: 'SStap197.exe',
    cmd: '"D:\\feizhongwen\\SSTap1.9.7\\SStap197.exe"'
  }
]
SStap197.exe is listening pid 5792
[
  {
    pid: 5792,
    ppid: 8288,
    bin: 'D:\\feizhongwen\\SSTap1.9.7\\SStap197.exe',
    name: 'SStap197.exe',
    cmd: '"D:\\feizhongwen\\SSTap1.9.7\\SStap197.exe"'
  }
]
SStap197.exe is listening port 25379
PS D:\port_check>

from find-process.

Danjuanlab avatar Danjuanlab commented on June 10, 2024

同上!当检索的进程名字为中文时,无返回值。因为从pid进行检索后反馈的结果中文名字是乱码。
可以增加一个改变编码的方式的参数,例如powershell中的chcp 65001
image

from find-process.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.