简体   繁体   English

为什么用 Zeit pkg 打包后我的 NodeJS 应用程序在 Linux mint cinnamon 19.1 中作为后台进程运行

[英]Why my NodeJS app after packing with Zeit pkg is running as a background process in Linux mint cinnamon 19.1

Hello!你好!

I am using Linux mint cinnamon 19.1 and I have some NodeJS project and want packing to a single executable using zeit pkg targeting to platform Linux and Windows.我正在使用 Linux mint cinnamon 19.1,并且我有一些 NodeJS 项目,并希望使用针对平台 Linux 和 ZAEA23489CE3AA9B6406EBB28E0CDA 的zeit pkg打包到单个可执行文件。 Process packaging is running well, but...流程打包运行良好,但...

The problem is问题是

When I open that executable with double click the app is running in background process automatically in Linux mint cinnamon 19.1 it didn't show the terminal, the error, also is hard to stop the process I have to do some netstat and kill processid当我双击打开该可执行文件时,应用程序在 Linux mint cinnamon 19.1 中自动在后台进程中运行它没有显示终端,错误,也很难停止进程我必须做一些netstatkill processid

I found the same issue and also this issue and have not been answered我发现了同样的问题,也发现了这个问题,但没有得到回答

My solution我的解决方案

I have a solution that comes to mind with child_process modules, and spawn('gnome-terminal').exec('node my-node.app') and of course it didn't work because .exec() diferrent prototype, and for now I am still can't find how to do spawn terminal and exec the command How to do spawn terminal and exec the command in the terminal that I have spawned我想到了一个关于child_process模块和spawn('gnome-terminal').exec('node my-node.app')的解决方案,当然它不起作用,因为.exec()原型不同,并且现在我仍然找不到如何生成终端并执行命令如何生成终端并在我生成的终端中执行命令

You just only need use .exec() not .spawn()你只需要使用.exec()而不是.spawn()

See this for more detail有关更多详细信息,请参阅此

const os = require('os');
const child_process = require('child_process');

if (os.platform() === 'linux') {
    child_process.exec('gnome-terminal -x bash -c "node your-node.js; exec bash"', 
    function(err, out, derr) {
        console.log(err);
        console.log(out);
        console.log(derr);
    });
}

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

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