Skip to content

child_process spawn does not pass environment key-value pairs on Windows #34667

Closed
@beliayeu

Description

@beliayeu
  • Version: 12.18.3
  • Platform: 64-bit Windows

What steps will reproduce the bug?

require('child_process').spawn('node', ['-pe', 'process.env.PATH'], {
  stdio: 'inherit',
  shell: true,
  env: {
    ...process.env,
    PATH: process.env.PATH + require('path').delimiter + __dirname,
  }
});

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

require('child_process').spawn('node', ['-pe', 'process.env.PATH'], {
  stdio: 'inherit',
  shell: true,
  env: {
    ...process.env,
    PATH: process.env.PATH + require('path').delimiter + __dirname,
    FAKEENV: 'FAKEVALUE',
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.questionIssues that look for answers.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions