We are using the JVM 32-bit on the Windows 64-bit operating system and I'm trying to know the actual OS arch value in java.
System.getProperty("os.name");
This ways gives the values as x86.
As mentioned here https://stackoverflow.com/a/5940770/5662508
But 64 bit Windows platforms will lie to the JVM if it is a 32 bit JVM. Actually 64 bit Windows will lie to any 32 bit process about the environment to help old 32 bit programs work properly on a 64 bit OS. Read the MSDN article about WOW64 for more information.
As a result of WOW64, a 32 bit JVM calling System.getProperty("os.arch") will return "x86". If you want to get the real architecture of the underlying OS on Windows, use the following logic:
So I have tried using the System.getenv("PROCESSOR_ARCHITECTURE") as well. This also gives the x86 in the Java output, but when I execute the same from the command prompt it gives following output.
C:\Users\Administrator\Desktop>echo %PROCESSOR_ARCHITECTURE%
AMD64
C:\Users\Administrator\Desktop>echo %PROCESSOR_ARCHITEW6432%
%PROCESSOR_ARCHITEW6432%
Neither PROCESSOR_ARCHITECTURE or PROCESSOR_ARCHITEW6432 not working in my case.
My Java class
public class Test {
public static void main(String[] args) {
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
System.out.println(osArch);
try {
String procArch = System.getenv("PROCESSOR_ARCHITECTURE");
System.out.println(procArch);
if (osName.toLowerCase().contains("windows") && "x86".equals(osArch) && null != procArch) {
System.out.println("in side");
osArch = procArch.toLowerCase();
}
} catch (Exception e) {
}
System.out.println(osArch);
}
}
output:
x86
x86
in side
x86
How can we get the actual processor architetecture value?