Browse Source

go

main
583641232@qq.com 1 year ago
parent
commit
5ab71e4b5e
  1. 16
      main.js

16
main.js

@ -23,7 +23,7 @@ function createWindow () {
// Open the DevTools.
mainWindow.webContents.openDevTools()
//mainWindow.webContents.openDevTools()
}
// This method will be called when Electron has finished
@ -47,13 +47,7 @@ app.on('window-all-closed', function () {
})
app.on('before-quit', () => {
getJavaProcessIdByPort(30523);
});
function getJavaProcessIdByPort(port) {
let pid = null;
let port = 30523;
exec(`netstat -ano | findstr :${port}`, (error, stdout, stderr) => {
// 查找stdout中匹配端口的行,并提取PID
if (stdout) {
@ -61,14 +55,16 @@ function getJavaProcessIdByPort(port) {
for (const line of lines) {
const pidMatch = line.match(/LISTENING\s+(\d+)/);;
if (pidMatch) {
pid = pidMatch[1];
let pid = pidMatch[1];
require('child_process').execSync(`taskkill /PID ${pid} -t -f`);
return;
}
}
}
});
}
});
// In this file you can include the rest of your app's specific main process

Loading…
Cancel
Save