From 310c5dbffce10dd86dbb151a4331240afb861d0d Mon Sep 17 00:00:00 2001 From: Matthew Francis Brunetti Date: Sun, 27 Sep 2020 15:00:07 -0400 Subject: [PATCH] child_process: add ChildProcess 'spawn' event The new event signals that the subprocess has spawned successfully and no 'error' event will be emitted from failing to spawn. Fixes: https://github.com/nodejs/node/issues/35288 --- doc/api/child_process.md | 15 +++++++++++ lib/internal/child_process.js | 7 +++++ .../test-child-process-spawn-error.js | 2 ++ .../test-child-process-spawn-event.js | 27 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 test/parallel/test-child-process-spawn-event.js diff --git a/doc/api/child_process.md b/doc/api/child_process.md index 235a2a80e71e2a..4e5801b2496d2a 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -1033,6 +1033,21 @@ child process, the `message` argument can contain data that JSON is not able to represent. See [Advanced serialization][] for more details. +### Event: `'spawn'` + + +The `'spawn'` event is emitted once the child process has spawned successfully. + +If emitted, the `'spawn'` event comes before all other events and before any +data is received via `stdout` or `stderr`. + +The `'spawn'` event will fire regardless of whether an error occurs **within** +the spawned process. For example, if `bash some-command` spawns successfully, +the `'spawn'` event will fire, though `bash` may fail to spawn `some-command`. +This caveat also applies when using `{ shell: true }`. + ### `subprocess.channel`