Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

child_process set parent process environment variable #7411

Closed
guileen opened this issue Apr 6, 2014 · 1 comment
Closed

child_process set parent process environment variable #7411

guileen opened this issue Apr 6, 2014 · 1 comment

Comments

@guileen
Copy link

guileen commented Apr 6, 2014

In bash, I can execute sh ~/.profile can change my environment. But I execute below code in nodejs not change my process.env

child_process.spawn('sh', ['/home/user/.profile'])
@tjfontaine
Copy link

Right, that's unfortunately just not going to work, node is a different beast with different requirements from bash. If you want environment variables from that subshell you will have to do some extra work, something like:

var cmd = 'source .profile; node -pe "JSON.stringify(process.env)"';
child_process.exec(cmd, function(code, stdout, stderr) {
  console.log(JSON.parse(stdout));
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants