find-process
find-process copied to clipboard
windows系统中程序路径中有中文就会检测失败
windows系统中如果程序路径中有中文就会检测失败。无论检测pid 还是检测占用的 port 都会失败
请给一下具体的报错信息
测试过程: 程序路径 :“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>