Repository navigation
child_process spawn does not pass environment key-value pairs on Windows #34667
Description
Activity
This is probably a duplicate of #20605 and the copied
envobject contains a variant ofPATHwith different casing (e.g.Path).The documentation was updated (#32091) to say:
The command lookup will be performed using options.env.PATH environment variable if passed in options object, otherwise process.env.PATH will be used. To account for the fact that Windows environment variables are case-insensitive Node.js will lexicographically sort all env keys and choose the first one case-insensitively matching PATH to perform command lookup. This may lead to issues on Windows when passing objects to env option that have multiple variants of PATH variable.
- addedchild_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.questionIssues asking questions about Node.js.Issues asking questions about Node.js.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
on Aug 10, 2020 I'll close this as answered. Let me know if it should be reopened.
thanks, @richardlau, for providing the root cause.
what is your recommendation how to change PATH environment variable? should different casing variants be deleted during object copying? or is there a better API how to do it?env: { ...process.env, Path: undefined, PATH: process.env.PATH + require('path').delimiter + __dirname, }cc: @bnoordhuis
thanks, @richardlau, for providing the root cause.
what is your recommendation how to change PATH environment variable? should different casing variants be deleted during object copying? or is there a better API how to do it?env: { ...process.env, Path: undefined, PATH: process.env.PATH + require('path').delimiter + __dirname, }cc: @bnoordhuis
There should only be one variant of
PATHinprocess.envas it has accessors to handle case insensitivity on Windows. So something like this should work on Windows:env: { ...process.env, [Object.keys(process.env).find(x => x.toUpperCase() === 'PATH')]: process.env.PATH + require('path').delimiter + __dirname, }
Reacted by Andrei Beliayeu- added a commit that references this issue
on May 3, 2021
What steps will reproduce the bug?
Actual behavior: PATH environment variable is not updated in the spawned process.
How often does it reproduce? Is there a required condition?
Always on Windows. It is not an issue on OSX.
What is the expected behavior?
PATH environment variable should be updated in the spawned process.
What do you see instead?
add a fake env variable to the env object passed to spawn