nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

child_process.spawn in detached mode does not detach on Mac

Open erikjjohnson opened this issue 13 years ago • 3 comments

Mac OS X 10.8.4 nw: 0.7.2

Node's child_process spawn function takes an option 'detached' which is supposed to spawn the given command with no parent process (well, without nw being the parent at least). This option behaves as I would expect on Windows version of nw, and it behaves as I would expect on node on Mac, but in nw on Mac, the spawned process is still attached to nw. This is causing an issue where we can't update our nw application because we rely on detaching the update process from nw.

Here code that I believe reproduces this problem:

package.json

{ "name": "detached", "main": "index.html" }

index.html

# detached.js

var spawn = require('child_process').spawn;

console.log('Spawning delay in detached mode'); var s = spawn('node', [__dirname + '/delay.js'], { detached: true, stdio: 'ignore' }); s.unref();

console.log('Exiting detached - ' + process.pid + ' - ' + s.pid); process.exit();

delay.js

console.log('Delay start'); setTimeout(function () { console.log('Delay end'); }, 20000);

Run the above files in nw and the nw window will remain open for 20 seconds. It should close almost immediately.

Using node version 0.10.13, running this on my Mac as:

node detached.js

I can see the second node process (for delay.js) is running after the main detached process is gone, so it appears to be nw specific.

erikjjohnson avatar Sep 10 '13 23:09 erikjjohnson

Same issue here, how to fix?

sergiopvilar avatar Feb 02 '15 23:02 sergiopvilar

@sergiovilar do you mean it breaks again? what's the version of your NW?

rogerwang avatar Feb 03 '15 01:02 rogerwang

i have some java code and call it like this var cp = require('child_process'); cp.spawn(_self.javaPath, ['-jar', __dirname+'/'+_self.jarPath]);

it turn out

[2413:0326/101433:ERROR:nw_shell.cc(335)] Error: spawn java ENOENT at exports._errnoException (util.js:734:11) at Process.ChildProcess._handle.onexit (child_process.js:1022:32) at child_process.js:1115:20 at process._tickCallback (node.js:375:11) [2413:0326/101433:INFO:CONSOLE(125)] "Uncaught Error: spawn java ENOENT", source: events.js (125)

any ideas?

unijoy avatar Mar 26 '15 02:03 unijoy