3

While in developing mode, executing the exe is working well.

My code to launch the exe is

function LaunchExe() {
        var child = require('child_process').execFile;
        var executablePath = 'DemoExe/Sample.exe';
        var parameters = ['Hai', 'Test', 'Dat'];
        child(executablePath, parameters, function (err, data) {
            console.log(err)
            console.log(data.toString());
        });
}

But after packaging the Electron app, I can't launch the exe.

The command I use to build the exe is

electron-packager . --asar

Error code

 Error: spawn DemoExe/Sample.exe ENOENT
     at Process.ChildProcess._handle.onexit (internal/child_process.js:232)
     at onErrorNT (internal/child_process.js:407)
     at process._tickCallback (internal/process/next_tick.js:63)

Regards.

pushkin
  • 9,575
  • 15
  • 51
  • 95
Nandha
  • 375
  • 3
  • 23

2 Answers2

2

Got to work with following steps,

1.package the Electron app using command

electron-packager .

2.Path to exe

path.join(__dirname, "DemoExe", "Sample.exe")

Nandha
  • 375
  • 3
  • 23
1

Is your project with angular?

Maybe this can help, but I had problems too with electron-packager.

So I suggest you to use electron builder : https://www.electron.build

Fist you need to add a file at root called electron-builder.json and it shoul'd contain the following (you need to update productname and icons location):

{
  "productName": "projectname",
  "appId": "org.project.projectname",
  "artifactName": "${productName}-setup-${version}.${ext}",
  "directories": {
    "output": "builds/"
  },
  "files": [
    "dist/",
    "node_modules/",
    "package.json",
    "**/*",
    "!**/*.ts",
    "!*.code-workspace",
    "!package-lock.json",
    "!src/",
    "!e2e/",
    "!hooks/",
    "!angular.json",
    "!_config.yml",
    "!karma.conf.js",
    "!tsconfig.json",
    "!tslint.json"
  ],
  "nsis": {
    "oneClick": false,
    "allowToChangeInstallationDirectory": true
  },
  "mac": {
    "icon": "src/favicon.ico"
  },
  "win": {
    "icon": "src/favicon.ico"
  },
  "linux": {
    "icon": "src/favicon.png"
  }
}

Then, you need to add those scripts to your package.json

"scripts": {
    "build:prod": "npm run build -- -c production",
    "package:windows": "npm run build:prod && electron-builder build --windows"
}

can compile the executable with

npm run package:windows

Also, don't forget to add electron builder into your dev dependencies :

yarn add electron-builder --dev

the executable with be located into /builds

Francis Robitaille
  • 575
  • 1
  • 5
  • 18