From 8169902b40d25e7b33803d6703788d1d512403a4 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 bfe7850ad0ddd3..0f78ba9d44e404 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -1036,6 +1036,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`