Skip to content

Commit

Permalink
doc,child_process: pid can be undefined when ENOENT
Browse files Browse the repository at this point in the history
From the code `nodejs@8` and up should behave the same:
github.com/nodejs/node/blame/v8.17.0/lib/internal/child_process.js#L290

And a short test snippet:
```js
const { spawn } = require('child_process')

const subProcess = spawn('non-exist-command')
subProcess.on('error', (error) =>
	console.warn('mute Unhandled "error" event:', error))
console.log('- pid:', subProcess.pid)
process.nextTick(() => console.log('- after error emit'))
console.log('== end of test ==')
```

Note: the sync spawn result `pid` currently do not follow this pattern.

Co-authored-by: Rich Trott <rtrott@gmail.com>

PR-URL: #37014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
dr-js authored and targos committed Feb 28, 2021
1 parent 4f41900 commit f20ce47
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1253,9 +1253,11 @@ does not indicate that the child process has been terminated.
added: v0.1.90
-->

* {integer}
* {integer|undefined}

Returns the process identifier (PID) of the child process.
Returns the process identifier (PID) of the child process. If the child process
fails to spawn due to errors, then the value is `undefined` and `error` is
emitted.

```js
const { spawn } = require('child_process');
Expand Down

0 comments on commit f20ce47

Please sign in to comment.