Skip to content

Commit a3c564b

Browse files
dr-jstargos
authored andcommitted
doc,child_process: pid can be undefined when ENOENT
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 <[email protected]> PR-URL: #37014 Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 605cb4c commit a3c564b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

doc/api/child_process.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,11 @@ does not indicate that the child process has been terminated.
12431243
added: v0.1.90
12441244
-->
12451245

1246-
* {integer}
1246+
* {integer|undefined}
12471247

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

12501252
```js
12511253
const { spawn } = require('child_process');

0 commit comments

Comments
 (0)