const { exec } = require('child_process');
const path = require('path');
const process = require('process');
const nw = require('nw.gui');
import { message } from 'antd';
import indexStore from "@/pages/layout/store";
// 打开进程
export function openExe() {
const appPath = path.dirname(process.execPath); // 获取当前运行的路径
exec(`"` + appPath + "\\Server.exe" + `"`, (error, stdout, stderr) => {
if (error) {
console.log('Error: ' + error.code, error.stack);
message.error("Server.exe打开失败");
return;
}
indexStore.serverStart = true // Server.exe是否启动
console.log('openExe: ', stdout, stderr);
});
};
//关闭进程
export function closeExe() {
exec('taskkill /im Server.exe -f', function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: ' + error.code);
return;
}
console.log('closeExe: ', stdout, stderr);
});
};
我是react项目,项目里面使用
const { exec } = require('child_process');
const path = require('path');
const process = require('process');
需要在项目中配置
如下: