electron-builder --win portable打包成单文件后调用子进程启动内部封装进的一个程序提示找不到文件
require('child_process').exec('start file:///static/w.exe');
其中w.exe放在与src平行的static文件夹下,build后dist/static下面能看到有这个文件w.exe
但是每次运行执行这里的时候就会报 windows找到不文件 file:///static/w.exe,请确认文件是否存在。
除这个外其它一切功能正常。
有人遇到过类似问题吗?是怎么解决的呢?感谢
版本信息如下:
"vue": "^2.5.2",
"vue-router": "^3.0.1"
"electron-serve": "^1.1.0",
"electron": "^19.0.3",
"electron-builder": "^23.0.3",
electron的main.js代码如下:
```javascript
const {app, BrowserWindow, ipcMain, Menu, shell} = require('electron');
const path = require('path');
const url = require('url');
const serve = require('electron-serve');
const loadURL = serve({directory: './dist'});
let mainWindow;
function createWindow() {
Menu.setApplicationMenu(null); //隐藏菜单栏
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: true, //隐藏窗口边框
resizable: false, //禁止调整窗口大小
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
}
});
loadURL(mainWindow);
//mainWindow.loadURL('app://index.html');
mainWindow.webContents.openDevTools({ detach: true }); // 自动打开调试台
mainWindow.on('closed', function () { mainWindow = null; });
require('child_process').exec('start file:///static/w.exe');
//shell.openPath('file:///static/Wow.exe');
}
app.on('ready', createWindow);
app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit(); });
app.on('activate', function () { if (mainWindow === null) createWindow(); });
const gotTheLock = app.requestSingleInstanceLock()
if (!app.requestSingleInstanceLock()) app.quit(); //防止多开
```