|
|
@ -1,6 +1,6 @@ |
|
|
|
// Modules to control application life and create native browser window
|
|
|
|
const { app, BrowserWindow } = require('electron') |
|
|
|
const { exec } = require('child_process'); |
|
|
|
const { execSync } = require('child_process'); |
|
|
|
const path = require('node:path') |
|
|
|
|
|
|
|
function createWindow () { |
|
|
@ -47,21 +47,25 @@ app.on('window-all-closed', function () { |
|
|
|
}) |
|
|
|
|
|
|
|
app.on('before-quit', () => { |
|
|
|
// 获取端口
|
|
|
|
let port = 30523; |
|
|
|
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) { |
|
|
|
let pid = pidMatch[1]; |
|
|
|
require('child_process').execSync(`taskkill /PID ${pid} -t -f`); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 执行杀死进程的操作
|
|
|
|
try { |
|
|
|
const command = `netstat -ano | findstr :${port}`; |
|
|
|
const output = execSync(command).toString(); |
|
|
|
const lines = output.trim().split('\n'); |
|
|
|
for (const line of lines) { |
|
|
|
const pidMatch = line.match(/LISTENING\s+(\d+)/); |
|
|
|
if (pidMatch) { |
|
|
|
const pid = pidMatch[1]; |
|
|
|
execSync(`taskkill /PID ${pid} -t -f`); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} catch (error) { |
|
|
|
console.error('无法杀死进程', error); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|