在electron 主程序,一般未main中
// exe地址 let servicePath = 'resources/service/win-unpacked/vue3-ts-music.exe' if(process.env.NODE_ENV === 'development') { servicePath = 'service/win-unpacked/vue3-ts-music.exe' }app.whenReady().then(() => { // electron/index.js var cp = require("child_process"); // 调后台服务 serivePath: exe所在的路径 cp.execFile(servicePath, [], function (err, stdout, stderr) { if (err) { console.error(err); } console.log('stdout:', stdout) console.log('stderr:', stderr) }); // Set app user model id for windows electronApp.setAppUserModelId('com.electron') // Default open or close DevTools by F12 in development // and ignore CommandOrControl + R in production. // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils app.on('browser-window-created', (_, window) => { optimizer.watchWindowShortcuts(window) }) // IPC test ipcMain.on('ping', () => console.log('pong')) createWindow() app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) app.on('quit', () => { // 关闭应用程序,结束后台服务vue3-ts-music.exe cp.exec('taskkill /fi "imagename eq vue3-ts-music.exe" /f', function(err, stdout, stderr) { if (err) return console.log(err) }) })标签:exe,console,err,app,ts,electron,调用 From: https://www.cnblogs.com/fhysy/p/18281446