Skip to content

Commit

Permalink
doc: clarify path search in child_process.spawn
Browse files Browse the repository at this point in the history
The documentation about command lookup could be more clear and note
differences between Windows and Linux/OSX.
Current text gives the impression that if one passes `options.env`
without `PATH`, the path search will fall back on `process.env.PATH`.
In reality, passing environment without `PATH` to `execvp` causes it
to look for the binary only in `/usr/bin:/bin`.
Also Windows behaves different and more in line with the current
documentation text.

PR-URL: #41418
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
zobo authored and danielleadams committed Apr 24, 2022
1 parent 6d422ad commit 3188dcb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions doc/api/child_process.md
Expand Up @@ -36,8 +36,11 @@ identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }`
option if the output will not be consumed.

The command lookup is performed using the `options.env.PATH` environment
variable if it is in the `options` object. Otherwise, `process.env.PATH` is
used.
variable if `env` is in the `options` object. Otherwise, `process.env.PATH` is
used. If `options.env` is set without `PATH`, lookup on Unix is performed
on a default search path search of `/usr/bin:/bin` (see your operating system's
manual for execvpe/execvp), on Windows the current processes environment
variable `PATH` is used.

On Windows, environment variables are case-insensitive. Node.js
lexicographically sorts the `env` keys and uses the first one that
Expand Down

0 comments on commit 3188dcb

Please sign in to comment.