简体   繁体   English

打包电子应用程序后,节点子进程立即退出

[英]Node child process exits immediately after packing the electron app

I have this piece of code in the GUI part of my electron app which works perfectly alright when run from the terminal. 我的电子应用程序的GUI部分中有这段代码,从终端运行时可以正常运行。 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. 最初,子进程立即终止,并给出代码127,我通过使用此处讨论的“修复路径”模块来解析了该代码。 https://github.com/electron/electron/issues/7688 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. 即使在此之后,该过程也会立即以代码1退出,我无法解决此问题,因为没有错误报告。 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!");
});

One can use child.stderr data event handler to catch the error. 可以使用child.stderr数据事件处理程序来捕获错误。 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://medium.freecodecamp.org/node-js-child-processes-everything-you-need-to-know-e69498fe970a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM