1.根据端口号,查询进程信息命令:
netstat -aon | findstr "端口号"
2.根据pid杀死进程命令:
taskkill /F /pid 进程号
function exec(cmd) {
return require('child_process')
.execSync(cmd)
.toString()
.trim()
}
let port = 3000
let stdout = exec(`netstat -aon | findstr ${port}`)
let line = stdout.split('\n')[0]; //第一行信息
let p = line.trim().split(/\s+/);
let pid = p[4]
exec(`taskkill /F /pid ${pid}`)
console.log()
网友评论