Skip to content

调用第三方类库

在项目中,通常需要调用(打开)第三方软件,如exe、bash脚本、dll库等

额外资源目录

bash
./build/extraResources

内部逻辑

  • 生成软件时,将 额外资源目录 一起打进软件安装包

  • 软件安装后,将资源解压到:软件安装位置/resources/extraResources

使用

bash
# 打包前后资源路径不同

# Ps.getExtraResourcesDir()会自动判断当前是打包前,还是打包后
let softwarePath = '';
softwarePath = path.join(Ps.getExtraResourcesDir(), softName);

# demo已经在项目中,请查看
# 方法一
/**
 * 调用其它程序
 */
openSoftware (softName) {
  .......
}

# 方法二 (推荐)
框架提供了 cross 模块,提供跨平台的 api 来调用第三方程序

示例说明

demo 中 powershell.exe 软件位置

bash
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

# 把它放到 ./build/extraResources 资源目录中,并测试