Search code examples
node.jselectronpidchild-processspawn

I get a wrong pid with child_process.spawn


I have problem in an Electron app and reduce the problem to a simple testspawn.js run in node

var spawn = require('child_process').spawn,
exp  = spawn('explorer', ['d:'],{detached:true}); //same thing detached or not
console.log('Spawned child pid: ' + exp.pid);

When I run node testspawn.js an explorer in the D: directory is showing but the console say: Spawned child pid: 5880.

BUT the Task Manager of Windows say : enter image description here

As I want at the end kill the explorer when I don't need it anymore, noway to have the right pid. What is the thing I'm missing ? . Completely lost ...


Solution

  • Further to my last comment, I don't have all the aswers but my case got a workaround ...