NodeJS: exit parent, leave child alive

i am writing an utility. One command of this utility is to run an external application.

var child_process = require('child_process');
var fs = require('fs');

var out = fs.openSync('.../../log/out.log', 'a');
var err = fs.openSync('.../../log/err.log', 'a');

exports.Unref = function(app, argv) {

  var child = child_process.spawn(app, argv, {
    detached: true,
    stdio: [ 'ignore', out, err ]
  });
  child.unref();
  //process.exit(0);
};

Currently:

$ utility run app --some-args // run external app
    // cant enter next command while app is running

My Problem is that if i run this command, the terminal is locked while the "external" Application is running.

But the terminal window shouldn't be locked by the child_process.

i wanna run:

$ utility run app --some-args
$ next-command
$ next-command

The external Application (a desktop application) will be closed by hisself.

Like this:

$ subl server.js // this runs Sublime Text and passes a file to the editor
$ npm start // The terminal does not locked - i can execute next command while Sublime is still running

You know what i mean ^^?

Appending ['>>../../log/out.log', '2>>../../log/err.log'] to the end of argv instead of leaving two files open should work since it's the open file handles that are keeping the process alive.

Passing opened file descriptors in stdio in addition to detached: true will not work the way you expect because there is no way to unref() the file descriptors in the parent process and have it still work for the child process. Even if there was a way, I believe that when the parent process exited, the OS would clean up (close) the file descriptors it had open, which would cause problems for the detached child process.

The only possible way that this might have been able to work would have been by passing file descriptors to child processes, but that functionality was dropped several stable branches ago because the same functionality did not exist on some other platforms (read: Windows).