简体   繁体   中英

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. 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

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

You just only need use .exec() not .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);
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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