System.getenv() returns different value in Ultimate and Community Edition

Answered

I wrote a plugin that fetching Environmental variable from the system. I am using Mac OS Sierra (10.12.6).

1. When I tested this by running (:runIde) it in Community Edition, it printed out the correct list of Environmental variables,

2. When I tested this by running (:runIde) it in Ultimate Edition, it printed out the correct list of Environmental variables,

3. But when I built the plugin (.zip) and installed it in Ultimate Edition, it printed out only a subset of the Environmental variables.

What am I missing here?

Why does `System.getEnv()` behave differently?

2 comments
Comment actions Permalink

How do you start IntelliJ IDEA?

On Mac getting environment variables is tricky and would depend on many factors. How and where they are set, how the process is launched, etc.

Terminal and GUI apps will have access to a different set of variables.

See https://stackoverflow.com/a/26586170/104891 and other similar questions.

0
Comment actions Permalink

Yes, it seems I can't use `System.getEnv()`, since that behaves differently while testing and after built. So I was looking at how the Environment Variables dialog in the various Run Configuration were able to show the Parent Environment variables. I found the logic for that in :

EnvironmentVariablesTextFieldWithBrowseButton.showParentEnvironmentDialog()

So I too used the same logic, i.e, 

GeneralCommandLine().getParentEnvironment()

Now I am getting the consistent behavior everywhere.

2

Please sign in to leave a comment.