Comments (3)
请给一下具体的报错信息
from find-process.
测试过程:
程序路径 :“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.
同上!当检索的进程名字为中文时,无返回值。因为从pid进行检索后反馈的结果中文名字是乱码。
可以增加一个改变编码的方式的参数,例如powershell中的chcp 65001
from find-process.
Related Issues (20)
- Cannot find PID on Windows 10 when process with very long command line running HOT 2
- `matchName` throws TypeError: Cannot read property 'match' of undefined HOT 3
- Cannot find by port on Arch Linux HOT 3
- Command name with whitespaces is truncated on Mac OS HOT 1
- Provide port details (if binded) for find process PID HOT 1
- Doesn't support UDP ports HOT 1
- Feature Request: Return port in found processes HOT 1
- Does not work in container HOT 2
- TypeError: Cannot read property 'endsWith' of undefined HOT 1
- Not return processes when value is a `regular expression` HOT 2
- Security issue HOT 3
- Check the process owner or any mapping between user and process before killing process in Node JS HOT 1
- v1.4.5: Error: port must be a number HOT 1
- Upgrade to powershell on windows and Change Management HOT 2
- special characters in mac
- Matching by 'name' returns true if args field is empty
- Get-CimInstance is not available in older Powershell versions HOT 1
- How can I read the cpu usage of a process HOT 1
- Adding logging level configuration HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from find-process.