12-12
This commit is contained in:
@ -581,40 +581,22 @@ function windowAllClosed() {
|
||||
|
||||
console.log('所有窗口已关闭,执行清理脚本...');
|
||||
getServer().close(() => {
|
||||
|
||||
|
||||
const vbsScript = `
|
||||
Set WshShell = CreateObject("WScript.Shell")
|
||||
WshShell.Run "${stopBatPath.substring(1, 200)}", 0, False
|
||||
Set WshShell = Nothing
|
||||
`;
|
||||
const vbsPath = path.join(os.tmpdir(), 'run_bat_hidden.vbs');
|
||||
require('fs').writeFileSync(vbsPath, vbsScript, 'utf8');
|
||||
|
||||
// 2. 执行 VBS 脚本(零窗口)
|
||||
const batProcess = spawn('wscript.exe', [vbsPath], {
|
||||
detached: true,
|
||||
// 执行批处理文件
|
||||
const cleanupProcess = spawn('cmd.exe', ['/c', stopBatPath.substring(1, 200)], {
|
||||
stdio: 'ignore',
|
||||
windowsHide: true,
|
||||
});
|
||||
cleanupProcess.on('exit', (code) => {
|
||||
if (code === 0) {
|
||||
console.log(code)
|
||||
} else {
|
||||
console.log(`脚本执行失败,退出码:${code}`);
|
||||
}
|
||||
});
|
||||
|
||||
batProcess.unref();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // 执行批处理文件
|
||||
cleanupProcess.on('error', (error) => {
|
||||
console.log('error', error)
|
||||
});
|
||||
// const cleanupProcess = exec(stopBatPath.substring(1, 200), (error, stdout, stderr) => {
|
||||
// if (error) {
|
||||
// console.error(`清理脚本执行失败: ${error.message}`);
|
||||
@ -630,12 +612,11 @@ Set WshShell = Nothing
|
||||
// }
|
||||
// });
|
||||
|
||||
// // 监听子进程退出事件(确保即使脚本出错也能退出)
|
||||
// cleanupProcess.on('exit', (code) => {
|
||||
// console.log(`清理脚本退出,代码: ${code}`);
|
||||
// });
|
||||
cleanupProcess.unref();
|
||||
|
||||
forceQuit();
|
||||
setTimeout(() => {
|
||||
forceQuit();
|
||||
}, 500);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user