在项目中,通常需要调用(打开)第三方软件,如exe、bash脚本、dll库等;
框架提供了资源目录:./build/extraResources
原理:
- 生成软件时,将 资源目录 一起打进软件安装包
- 软件安装后,将资源解压到:软件安装位置/resources/extraResources
资源目录:
./build/extraResources
使用:
# 资源路径不同let softwarePath = '';# 旧语法if (electronApp.isPackaged) {// 打包后// execDir为 应用程序 exe\dmg\dep\类库 等,所在目录softwarePath = path.join(this.app.config.execDir, "resources", "extraResources", softName);} else {// 打包前softwarePath = path.join(this.app.config.execDir, "build", "extraResources", softName);}# 新语法,getExtraResourcesDir()会自动判断当前是打包前,还是打包后softwarePath = path.join(Utils.getExtraResourcesDir(), softName);# demo已经在项目中,请查看/*** 调用其它程序*/openSoftware (softName) {.......}
举例:demo中powershell.exe 软件位置
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe# 把它放到 ./build/extraResources 资源目录中,并测试
