简体   繁体   English

System.getenv()仅在调试IntelliJ插件时正常工作

[英]System.getenv() only works properly when debugging IntelliJ plugin

I'm running IntelliJ 13 (on OS X Yosemite) and trying to get the Go IDEA plugin working. 我正在运行IntelliJ 13(在OS X Yosemite上),并试图使Go IDEA插件正常工作。 When I debugged the application to try to find what the problem is, I found that for some reason the slave IDEA that's ran gets my environment just fine. 当我调试应用程序以尝试查找问题所在时,我发现由于某种原因,运行的从IDEA使我的环境正常。

Normally when trying to run anything involving the go utility, an exception is thrown. 通常,当尝试运行涉及go实用程序的任何内容时,都会引发异常。 The plugin will execute commands by executing go <args> with the environment vars: 该插件将通过使用环境vars执行go <args>来执行命令:

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command, goEnv, new File(projectDir));

If I change the go command to be the full path of the go binary, all works fine. 如果我改变了go命令是的完整路径go二进制,一切工作正常。 When debugging however, I don't have to change the path and it still succeeds. 但是,在调试时,我不必更改路径,它仍然可以成功。

The plugin has an action which prints out the environment which calls System.getenv() 该插件有一个动作,可以打印出调用System.getenv() 的环境。

GoToolWindow toolWindow = this.getGoToolWindow(project);
toolWindow.showAndCreate(project);
toolWindow.clearConsoleView();

String[] sysEnv = GoSdkUtil.convertEnvMapToArray(System.getenv());


toolWindow.printNormalMessage(String.format("%s -> %s%n", "Project dir", projectDir));
for (String env : sysEnv) {
    toolWindow.printNormalMessage(String.format("%s%n", env));
}

When running IDEA normally, this outputs: 正常运行IDEA时,输出:

Project dir -> /Users/lander/Development/downloader
SHELL=/bin/zsh
TMPDIR=/var/folders/6y/xxqr1vqn6q7c_ttvdgjt7p1w0000gn/T/
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PATH=/usr/bin:/bin:/usr/sbin:/sbin
XPC_FLAGS=0x0
USER=lander
HOME=/Users/lander
XPC_SERVICE_NAME=com.jetbrains.intellij.43484
LOGNAME=lander
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.tV9zH4QXK4/Render
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BCyPknIo2V/Listeners

And when debugging the plugin: 并且在调试插件时:

Project dir -> /Users/lander/IdeaProjects/gotest
ZSH=/Users/lander/.oh-my-zsh
com.apple.java.jvmMode=client
GREP_OPTIONS=--color=auto --exclude-dir=.cvs --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
GOROOT=/usr/local/opt/go/libexec
XPC_FLAGS=0x0
JAVA_MAIN_CLASS_14389=com.intellij.idea.Main
LOGNAME=lander
GREP_COLOR=1;32
ZSH_TMUX_TERM=screen
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.BCyPknIo2V/Listeners
OLDPWD=/Applications/IntelliJ IDEA 13.app/Contents/bin
SHELL=/bin/zsh
LC_CTYPE=
TMPDIR=/var/folders/6y/xxqr1vqn6q7c_ttvdgjt7p1w0000gn/T/
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/Users/lander/go/bin
VERSIONER_PYTHON_VERSION=2.7
GOPATH=/Users/lander/go
LESS=-R
USER=lander
com.apple.java.jvmTask=CommandLine_Manual.java
ZSH_TMUX_AUTOSTARTED=true
PAGER=less
HOME=/Users/lander
XPC_SERVICE_NAME=0
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.tV9zH4QXK4/Render
LSCOLORS=Gxfxcxdxbxegedabagacad
_ZSH_TMUX_FIXED_CONFIG=/Users/lander/.oh-my-zsh/plugins/tmux/tmux.extra.conf
VERSIONER_PYTHON_PREFER_32_BIT=no

What's the reason for the difference? 差异的原因是什么?

According to a JetBrains employee , this is because the slave instance is launched with the environment given by an external script that's ran. JetBrains的一名雇员称 ,这是因为从属实例是在运行的外部脚本给定的环境下启动的。 Plugins in the parent process should not call System.getenv() and instead use the EnvironmentUtil . 父进程中的插件不应调用System.getenv() ,而应使用EnvironmentUtil

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM