mirror of
https://github.com/QYG2297248353/IYUUPlus-Windows.git
synced 2025-03-04 03:34:25 +08:00
修复环境变量
This commit is contained in:
parent
44a602116d
commit
e71dda3b67
@ -7,7 +7,8 @@ module.exports = {
|
||||
icon: 'iyuu.png',
|
||||
extraResource: [
|
||||
'run/',
|
||||
'iyuu/'
|
||||
'iyuu/',
|
||||
"run.bat"
|
||||
]
|
||||
},
|
||||
rebuildConfig: {},
|
||||
|
3
run.bat
3
run.bat
@ -1,3 +1,4 @@
|
||||
@echo off
|
||||
CHCP 65001
|
||||
.\run\php-8.3.8-x64\php.exe .\iyuu\windows.php
|
||||
pause
|
||||
pause
|
||||
|
@ -1,4 +1,4 @@
|
||||
const { spawn, exec } = require('child_process');
|
||||
const { spawn, exec, execFile } = require('child_process');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const log = require('electron-log')
|
||||
@ -24,25 +24,54 @@ function startServer() {
|
||||
}
|
||||
|
||||
const cmdPath = getCmdPath(resourcePath);
|
||||
const args = [path.join(resourcePath, 'iyuu', 'windows.php')];
|
||||
const batPath = path.join(resourcePath, 'run.bat');
|
||||
const workingDirectory = path.resolve(resourcePath);
|
||||
|
||||
const env = { ...process.env };
|
||||
const phpDir = path.dirname(cmdPath);
|
||||
env.PATH = `${phpDir}${path.delimiter}${env.PATH}`;
|
||||
env.Path = `${phpDir};${env.Path}`;
|
||||
|
||||
serverProcess = spawn(cmdPath, args, {
|
||||
// serverProcess = exec(`C:\\Windows\\System32\\cmd.exe /c ${batPath}`, {
|
||||
// cwd: workingDirectory,
|
||||
// env: env,
|
||||
// windowsHide: true
|
||||
// }, (error, stdout, stderr) => {
|
||||
// if (error) {
|
||||
// log.error(`[IYUU] 服务启动错误: ${error.message}`);
|
||||
// return;
|
||||
// }
|
||||
// if (stderr) {
|
||||
// log.error(`[IYUU] 服务启动 stderr: ${stderr}`);
|
||||
// return;
|
||||
// }
|
||||
// log.info(`[IYUU] 服务启动成功: ${stdout}`);
|
||||
// });
|
||||
|
||||
serverProcess = execFile('cmd.exe', ['/c', batPath], {
|
||||
cwd: workingDirectory,
|
||||
stdio: ['inherit', 'pipe', 'inherit'],
|
||||
stdio: 'ignore',
|
||||
env: env,
|
||||
detached: true,
|
||||
windowsHide: true
|
||||
});
|
||||
|
||||
serverProcess.stdout.setEncoding('utf8');
|
||||
// serverProcess = spawn('cmd.exe', ['/c', batPath], {
|
||||
// cwd: workingDirectory,
|
||||
// stdio: 'ignore',
|
||||
// env: env,
|
||||
// detached: true,
|
||||
// windowsHide: true
|
||||
// });
|
||||
|
||||
serverProcess.unref();
|
||||
|
||||
if (serverProcess.stdout) {
|
||||
serverProcess.stdout.setEncoding('utf8');
|
||||
|
||||
serverProcess.stdout.on("data", function (data) {
|
||||
log.info("[IYUU] 服务启动成功");
|
||||
});
|
||||
}
|
||||
|
||||
serverProcess.stdout.on("data", function (data) {
|
||||
log.info("[IYUU] 服务启动成功");
|
||||
});
|
||||
serverProcess.on("close", function (code) {
|
||||
log.info("[IYUU] 服务退出:" + code);
|
||||
});
|
||||
@ -75,7 +104,9 @@ function stopServer() {
|
||||
|
||||
function restartServer() {
|
||||
stopServer();
|
||||
startServer();
|
||||
setTimeout(() => {
|
||||
startServer();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
module.exports = { startServer, stopServer, restartServer };
|
Loading…
x
Reference in New Issue
Block a user