Skip to content

Commit

Permalink
Detach the child process when waiting is false
Browse files Browse the repository at this point in the history
if waiting option is false set stdio to 'ignore' and detached to true so
that the child process is completely detached from the parent and it is
able to continue running after the parent exits.
  • Loading branch information
GAumala committed Sep 14, 2017
1 parent eb99a73 commit 2bfd1ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ module.exports = (target, opts) => {
}
}

if(!opts.wait) {
// The child process will NOT stay running in the background after
// the parent exits unless it is detached from the parent AND it
// ignores the parent's stdio file descriptor
cpOpts.stdio = 'ignore'
cpOpts.detached = true
}

args.push(target);

if (process.platform === 'darwin' && appArgs.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Type: `Object`
Type: `boolean`<br>
Default: `true`

Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app, and the app is completely detached from the node process that spawned it.

On Windows you have to explicitly specify an app for it to be able to wait.

Expand Down

0 comments on commit 2bfd1ee

Please sign in to comment.