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: https://github.com/nodejs/node/blame/v8.17.0/lib/internal/child_process.js#L290-L316

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>
  • Loading branch information
dr-js and Trott committed Feb 1, 2021
1 parent 683754c commit c7a9a6d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,9 @@ added: v0.1.90

* {integer}

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 like command or `cwd` not found (`ENOENT`), then
the value is `undefined` and `error` should emit on next tick.

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

0 comments on commit c7a9a6d

Please sign in to comment.