In node/io.js, by default, calling child_process.exec()
causes the child process to inherit all of the environment variables of the parent process. As I understand it, this is normal behavior for Windows' CreateProcess function.
However, this is problematic for me as the parent process (Atom) by default sets NODE_ENV
to production
, which, when leaked to child processes (e.g. a terminal app), causes obscure, sometimes serious problems downstream.
The only two possible solutions I can think of are setting the env
key of exec()
's options argument to either:
- An empty object. This causes the child process to receive a fresh set of system environment variables. The problem with this is that any user-specific environment variables are lost, e.g.
APPDATA
, resulting in even more problems downstream. - A copy of
process.env
where the offending variables are removed or modified as necessary. Works, but no way to know what the previous values of these variables were, so could very well be clobbering the original values anyways.
Is there a way in node/io.js to ensure that child processes do not inherit their parent's environment variables, but still have all of the current user's environment variables (e.g. APPDATA
)?
Running under Atom 1.0.2's embedded io.js (1.5.1), Windows 7 SP1 64-bit.