问题描述
我在电子应用程序的GUI部分有这段代码,从终端运行时效果很好。我使用'electron-packager'打包应用程序,然后我开始遇到一些问题。
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.
最初,子进程立即终止并提供代码127,我通过使用此处讨论的'fix-path'模块解析了该代码。
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
即使在此之后,该过程立即退出代码1,我无法解决此问题,因为没有报告错误。一旦子进程退出,有没有办法捕获此异常/错误?
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!");
});
推荐答案
可以使用child.stderr数据事件处理程序来捕获错误。我在我的脚本中添加了这段代码,我可以在控制台上调试输出问题。
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
这篇关于打包电子应用程序后,节点子进程立即退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!