簡體   English   中英

打包電子應用程序后,節點子進程立即退出

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

我的電子應用程序的GUI部分中有這段代碼,從終端運行時可以正常運行。 我使用“電子打包程序”打包了該應用程序,然后開始出現一些問題。

最初,子進程立即終止,並給出代碼127,我通過使用此處討論的“修復路徑”模塊來解析了該代碼。 https://github.com/electron/electron/issues/7688

即使在此之后,該過程也會立即以代碼1退出,我無法解決此問題,因為沒有錯誤報告。 一旦子進程退出,是否有辦法捕獲此異常/錯誤?

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數據事件處理程序來捕獲錯誤。 我在腳本中添加了這段代碼,並且能夠通過控制台上的輸出調試問題。

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

請參閱這篇文章,它可以幫助我解決此問題。 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