Node child process exits immediately after packing the electron app

北城余情 提交于 2019-12-23 05:00:26

问题


I have this piece of code in the GUI part of my electron app which works perfectly alright when run from the terminal. I have packaged the app using 'electron-packager', then I started getting some issue.

Initially, the child process was terminating immediately and giving code 127 which I resolved by using 'fix-path' module as discussed here. https://github.com/electron/electron/issues/7688

Even after this, the process exits immediately with a code 1, I am unable to resolve this as there is no error getting reported. Is there a way to catch this exception/error once the child process exits?

const fixPath = require('fix-path');
let launch = () => {
fixPath();

const path = "SOME PATH";
var command = 'node ' + 
              path + 
              ' -d ' +      
              ' -e ' +     
              ' -r ' +      
              ' -p ' + 30 +
              ' -w ' +     
              ' -g ' +     
              '-server__ ';


const child = childProcess.exec(command, {
  detached: true,   
  stdio: 'ignore'
});

child.on('error', (err) => {
  console.log("\n\t\tERROR: spawn failed! (" + err + ")");
});

child.on('exit', (code, signal) => {
  console.log(code);
  console.log("\n\t\tGUI: spawned completed it's work!");
});

回答1:


One can use child.stderr data event handler to catch the error. I added this piece of code in my script and I was able to debug the issue with the output on console.

child.stderr.on('data', function(data) {
  console.log('stdout: ' + data);
});

Refer this article which helped me to solve this issue. https://medium.freecodecamp.org/node-js-child-processes-everything-you-need-to-know-e69498fe970a



来源:https://stackoverflow.com/questions/51639238/node-child-process-exits-immediately-after-packing-the-electron-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!