Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process.exec considering process.env improvement #11861

Closed
KaiSchwarz-cnic opened this issue Mar 15, 2017 · 3 comments
Closed

child_process.exec considering process.env improvement #11861

KaiSchwarz-cnic opened this issue Mar 15, 2017 · 3 comments
Labels
child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js.

Comments

@KaiSchwarz-cnic
Copy link

KaiSchwarz-cnic commented Mar 15, 2017

  • Version: At least from 4.8.0 up to 6.10.0
  • Platform: debian 8
  • Subsystem: lib/child_process.js
var exec = require('child_process').exec;

var options = {
    env : {
        NODE_ENV : 'production'
    }
};
exec(command, options, function(err, stdout, stderr) {
  //do something here  
});

The above will loose all other process.env variables.
This might be correct behavior, but on the other hand I personally would have expected that exec does internally something like:

var env;
if (options.env){
    env = Object.assign({}, process.env, options.env);
} else {
   env = Object.assign({}, process.env);
}

and then using it further on. This makes every child process having the process.env with possibility to override specific env vars. I am not familiar with use cases or what other developers would expect, but at least the above way drops out that logic from customer apps and could feel comfortable.
Suppressing that with options.env = false could be an idea too.

So don't understand this as a reported bug, just an improvement idea you might think about.

Thanks!

@bnoordhuis bnoordhuis added child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js. labels Mar 15, 2017
@bnoordhuis
Copy link
Member

Thanks for the suggestion but the problem with that approach is that you can't specify a fully custom environment, you can't avoid inheriting from the existing environment.

As well, backwards compatibility is an issue. The current behavior has been around for a long time, changing it now would probably be quite disruptive to the ecosystem.

@cjihrig
Copy link
Contributor

cjihrig commented Mar 15, 2017

Yes, what Ben said. The only option would be another setting like appendEnv or something, but the existing workaround doesn't seem too difficult. The hardest part is remembering that you have to do it (I've been bitten by this before too). I'm going to close the issue as a "won't fix."

@cjihrig cjihrig closed this as completed Mar 15, 2017
@KaiSchwarz-cnic
Copy link
Author

No fear, I understand these reasons, I've basically expected this response. Thanks that you both had an eye on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

3 participants