2

I have my Electron app which I am packaging with electron-packager npm module. I want to execute an python application only by name from Nodejs module called child_process. When the application isn't packaged it works, but when I package it does not work. I noticed that the packaged app does not load PATH variable so it works only if I change it to absolute path to the script. But I want to make it platform independent, so it is not a solution for me.

Is there any way how can I "inject" PATH variable to the packaged application or any other solution?

WutchZone
  • 154
  • 1
  • 3
  • 13

2 Answers2

3

This is probably this PATH issue.

And you can fix it with this package.

const fixPath = require('fix-path');

fixPath();

console.log(process.env.PATH);
//=> '/usr/local/bin:/usr/bin'
Opsse
  • 1,851
  • 2
  • 22
  • 38
0

Are you using spawn to spin off your child process? If so, that is launched without a shell, therefore no PATH. However, you can force it to use a shell.

const myCmd = spawn('ls', args, { shell: true });

Alternatively, you could use exec which does run with a shell. Here's an article that goes into depth on the differences.

Chris Riebschlager
  • 1,323
  • 1
  • 8
  • 12