vue electron應(yīng)用調(diào)exe程序的實現(xiàn)步驟
描述
用Python寫了一個本地服務(wù)編譯成exe程序,在electron程序啟動后,自動執(zhí)行exe程序
實現(xiàn)
1. 使用node的child_process模塊可以執(zhí)行windows執(zhí)行,通過指令調(diào)exe程序
// electron/index.js
var cp = require("child_process");
// 調(diào)后臺服務(wù) serivePath: exe所在的路徑
serverProcss = cp.execFile(serivePath, [], function(err,stdout,stderr){
if(err){
console.error(err);
}
console.log("stdout:",stdout)
console.log("stderr:",stderr);
});2. 路徑問題
- 開發(fā)環(huán)境直接寫前端目錄下的路徑,比如我的exe程序放到了service目錄下,serivePath就可以設(shè)置為"service/xx.exe",
- 生產(chǎn)環(huán)境下,資源會放到resources目錄下,所以serivePath設(shè)置為"resources/service/xx.exe", 開發(fā)環(huán)境路徑生的service是因為我在package.json中配置了exe路徑
// 根據(jù)環(huán)境使用不同的路徑
let servicePath = 'resources/service/xx.exe'
if(process.env.NODE_ENV === 'development') {
servicePath = 'service/xx.exe'
}
//package.json
"extraResources": {
"from": "./service/",
"to": "service"
},開發(fā)路徑

安裝后的路徑

3. 增加:關(guān)閉electron程序結(jié)束exe服務(wù)
import { app, BrowserWindow, dialog , ipcMain } from 'electron'
app.on('quit', () => {
// 關(guān)閉應(yīng)用程序,結(jié)束后臺服務(wù)xx.exe
cp.exec('taskkill /fi "imagename eq xx.exe" /f', function(err, stdout, stderr) {
if(err) return console.log(err);
})
})到此這篇關(guān)于vue electron應(yīng)用調(diào)exe程序的實現(xiàn)步驟的文章就介紹到這了,更多相關(guān)vue electron調(diào)exe程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
VSCode使React?Vue代碼調(diào)試變得更爽
這篇文章主要為大家介紹了VSCode使React?Vue代碼調(diào)試變得更爽的使用方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07
JS 實現(xiàn)獲取對象屬性個數(shù)的方法小結(jié)
這篇文章主要介紹了JS 實現(xiàn)獲取對象屬性個數(shù)的方法,結(jié)合實例形式總結(jié)分析了JS 獲取對象屬性個數(shù)的三種常用方法,需要的朋友可以參考下2023-05-05
vue.js使用v-model實現(xiàn)表單元素(input) 雙向數(shù)據(jù)綁定功能示例
這篇文章主要介紹了vue.js使用v-model實現(xiàn)表單元素(input) 雙向數(shù)據(jù)綁定功能,結(jié)合完整實例形式分析了v-model實現(xiàn)表單input元素數(shù)據(jù)雙向綁定相關(guān)操作技巧,需要的朋友可以參考下2019-03-03

