我的一些代码在x64中失败,我开始挖掘,这是由于一些代码通过Runtime.getRuntime()调用本机的东西.exec()...
但是这段代码可能已经有几年了,它没有考虑到更新的操作系统,而且有些代码看起来像这样:
String osName = System.getProperty("os.name");
if (osName.equals("Windows NT") || osName.equals("Windows 2000") || osName.equals("Windows XP")) {
cmd = new String[3];
cmd[0] = WINDOWS_NT_2000_COMMAND_1;
cmd[1] = WINDOWS_NT_2000_COMMAND_2;
cmd[2] = command;
} else if (osName.equals("Windows 95") || osName.equals("Windows 98") || osName.equalsIgnoreCase("Windows ME")) {
cmd = new String[3];
cmd[0] = WINDOWS_9X_ME_COMMAND_1;
cmd[1] = WINDOWS_9X_ME_COMMAND_2;
cmd[2] = command;
Run Code Online (Sandbox Code Playgroud)
我想为所有新操作系统(w2008,Windows 7,...)修复此问题,但我无法访问各种主机,而且我不想在VM中安装只是为了查看值,有人在某处知道某些清单吗?还没找到.
编辑:我需要:Windows 7,Windows 2003,Windows 2008,Windows 2008R2此外,我不是1.6u18所以不用担心一些人提到的bug.
虽然这不是一个完整的解决方案,但您可以获得32位JDK并运行简单的代码打印os.name并os.version具有不同的兼容性设置.
以下是Windows 8.1盒子上不同JDK报告的os.name/ os.version值:
╔═════════════════╤════════════╤════════════╤════════════╤═══════════════╤═══════════════╤══════════════════════╤══════════════════════╗ ║ Java/OS version │ Windows 95 │ Windows 98 │ Windows XP │ Windows Vista │ Windows 7 │ Windows 8 │ Windows 8.1 ║ ╟─────────────────┼────────────┼────────────┼────────────┼───────────────┼───────────────┼──────────────────────┼──────────────────────╢ ║ 1.4.2 │ Windows 95 │ Windows 98 │ Windows XP │ Windows Vista │ Windows Vista │ Windows Vista │ Windows Vista ║ ║ │ 4.0 │ 4.10 │ 5.1 │ 6.0 │ 6.1 │ 6.2 │ 6.2 ║ ║ 1.5.0 │ Windows 95 │ Windows 98 │ Windows XP │ Windows Vista │ Windows 7 │ Windows NT (unknown) │ Windows NT (unknown) ║ ║ │ 4.0 │ 4.10 │ 5.1 │ 6.0 │ 6.1 │ 6.2 │ 6.2 ║ ║ 1.6.0 │ Windows 95 │ Windows 98 │ Windows XP │ Windows Vista │ Windows 7 │ Windows 8 │ Windows 8 ║ ║ │ 4.0 │ 4.10 │ 5.1 │ 6.0 │ 6.1 │ 6.2 │ 6.2 ║ ║ 1.7.0 │ Windows 95 │ Windows 98 │ Windows XP │ Windows Vista │ Windows 7 │ Windows 8 │ Windows 8.1 ║ ║ │ 4.0 │ 4.10 │ 5.1 │ 6.0 │ 6.1 │ 6.2 │ 6.3 ║ ║ 1.8.0 │ Windows 95 │ Windows 98 │ Windows XP │ Windows Vista │ Windows 7 │ Windows 8 │ Windows 8.1 ║ ║ │ 4.0 │ 4.10 │ 5.1 │ 6.0 │ 6.1 │ 6.2 │ 6.3 ║ ╚═════════════════╧════════════╧════════════╧════════════╧═══════════════╧═══════════════╧══════════════════════╧══════════════════════╝
很可能你可以改变代码说
if (osName.equals("Windows 95") || osName.equals("Windows 98") || osName.equalsIgnoreCase("Windows ME")) {
cmd = new String[3];
cmd[0] = WINDOWS_9X_ME_COMMAND_1;
cmd[1] = WINDOWS_9X_ME_COMMAND_2;
cmd[2] = command;
}
else {
cmd = new String[3];
cmd[0] = WINDOWS_NT_2000_COMMAND_1;
cmd[1] = WINDOWS_NT_2000_COMMAND_2;
cmd[2] = command;
}
Run Code Online (Sandbox Code Playgroud)
当Visual Cafe还活着的时候,我在赛门铁克处理了这个...我不建议这样做.问题是不同的供应商可以提供不同的字符串.我建议使用特定于操作系统的方法来确定平台.
您可以在Windows上使用"ver"实用程序,在Unix类型系统上使用"uname".
在Windows上使用"GetNativeSystemInfo"可能更好,但这需要本机代码.
我建议采用这种方式而不是依赖System.getProperty方法的原因是因为您只需要处理底层操作系统而不是操作系统顶部的JVM - 这就消除了不同虚拟机报告不同内容的问题同一个平台.
编辑:显然你必须尝试不同的方式获取信息,因为其中一些可能需要运行shell而不仅仅是命令.但如果你坚持使用bash它应该是好的.基本上尝试运行命令,直到其中一个工作...不漂亮,但它会工作.
| 归档时间: |
|
| 查看次数: |
34661 次 |
| 最近记录: |