Browse Source

go

main
583641232@qq.com 1 year ago
parent
commit
729b2e6219
  1. 26
      main.js

26
main.js

@ -1,5 +1,6 @@
// Modules to control application life and create native browser window // Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron') const { app, BrowserWindow } = require('electron')
const { exec } = require('child_process');
const path = require('node:path') const path = require('node:path')
function createWindow () { function createWindow () {
@ -45,5 +46,30 @@ app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit() if (process.platform !== 'darwin') app.quit()
}) })
app.on('before-quit', () => {
getJavaProcessIdByPort(30523);
});
function getJavaProcessIdByPort(port) {
let pid = null;
exec(`netstat -ano | findstr :${port}`, (error, stdout, stderr) => {
// 查找stdout中匹配端口的行,并提取PID
if (stdout) {
const lines = stdout.trim().split('\r\n');
for (const line of lines) {
const pidMatch = line.match(/LISTENING\s+(\d+)/);;
if (pidMatch) {
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 // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here. // code. You can also put them in separate files and require them here.
Loading…
Cancel
Save