From aa5b726f835c357c8be6b2da825d0e939a07f0a7 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 PR-URL: https://github.com/nodejs/node/pull/35369 Reviewed-By: Anna Henningsen Reviewed-By: Gireesh Punathil --- 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 2b6fabc3e1d293..6f6c81e253ff06 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -1039,6 +1039,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`