windows 如何从命令行检测 64 位 Java?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2268705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I detect 64-bit Java from the command line?
提问by djangofan
Is there any way to get at Java internal properties, such as sun.arch.data.model, from a command line on windows? I need a command to put in a batch script that will detect the java architecture type: 32-bit or 64-bit .
有没有办法从 Windows 上的命令行获取 Java 内部属性,例如sun.arch.data.model?我需要一个命令来放入一个批处理脚本来检测 java 架构类型: 32-bit 或 64-bit 。
采纳答案by jarnbjo
If you are using Sun's VM (and I would suppose other VMs have similar details in their version information), you can check for the string "64-Bit" in the output of "java -version":
如果您使用的是 Sun 的 VM(并且我认为其他 VM 在其版本信息中具有类似的详细信息),您可以在“java -version”的输出中检查字符串“64-Bit”:
java -version 2>&1 | find "64-Bit" >nul:
if errorlevel 1 (
echo 32-Bit
) else (
echo 64-Bit
)
回答by stoneboy
jarnbjo's script is for Windows. In Unix shell, you can use the following script.
jarnbjo 的脚本适用于 Windows。在 Unix shell 中,您可以使用以下脚本。
#!/bin/sh BIT=`java -version 2>&1` case "$BIT" in *64-Bit*) echo "64-Bit" ;; *) echo "32-Bit" ;; esac
回答by rlovtang
If you install Groovyyou can use
如果您安装Groovy,您可以使用
groovy -e "System.properties.each{println it}"
for all properties, and
对于所有属性,以及
groovy -e "println System.properties['sun.arch.data.model']"
for specific properties.
对于特定属性。
Installing Groovy is as easy as extracting a zip and add to path.
安装 Groovy 就像提取一个 zip 文件并添加到路径一样简单。