I have a Electron project which executes some python script using NodeJS's child_process module.
My python script is in the root folder of my project.
Here's how I call the python script:
let py = spawn('python',['ResolvePosition.py', obsFilePath, navFilePath])
py.stdout.on('data', data => console.log('data : ', data.toString()))
py.on('close', ()=>{
// Python ends, do stuff
})
This works fine if I run my electron app with npm start
When I build an executable for Windows using the npm module electron-builder and run the executable from dist/win-unpacked/my-app.exe, this won't work, it seems that my script is not accesible with python ./my-script-py.
So, how can I make this code works for the built project?
解决方案
You can include the script in extraResources:
"build": {
"extraResources": "python_scripts",
...
And then the dir will be at the app root:
let python = spawn('python', [path.join(app.getAppPath(), '..', 'python_scripts/my_script.py'])