欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

同样一段java代码,在eclipse的run模式与debug模式为什么结果会不一致??  

程序员文章站 2022-06-13 21:50:46
...
package com.aking.test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;

public class TestEnv {
public static Properties getEnvVars() throws Throwable {
Process p = null;
Properties envVars = new Properties();
Runtime r = Runtime.getRuntime();
String OS = System.getProperty("os.name").toLowerCase();
// System.out.println(OS);
if (OS.indexOf("windows 9") > -1) {
p = r.exec("command.com /c set");
} else if (OS.indexOf("windows") > -1) {
// thanks to JuanFran for the xp fix!
p = r.exec("cmd.exe /c set");
} else {
// our last hope, we assume Unix (thanks to H. Ware for the fix)
p = r.exec("env");
}

BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
int idx = line.indexOf('=');
String key = line.substring(0, idx);
String value = line.substring(idx + 1);
envVars.setProperty(key, value);
System.out.println(line);
}
return envVars;
}

public static void main(String args[]) {
try {
Properties p = TestEnv.getEnvVars();
System.out.println("the current value of TEMP is : "
+ p.getProperty("TEMP"));
} catch (Throwable e) {
e.printStackTrace();
}
}
}

就这么一段代码,获取widows系统的环境变量,为什么debug模式下的结果与run模式下的结果会不一样呢?在run模式下是正常的,大小写区分的。但是在debug模式下,环境变量名称全成了大写???

在IntelliJ IDEA环境下验证同样的代码,run模式和debug模式得到的结果是一致的。因此推断,应该是eclipseIDE debug插件的问题。