diff options
author | David Herman <davidherman@google.com> | 2014-12-10 09:49:47 -0800 |
---|---|---|
committer | David Herman <davidherman@google.com> | 2014-12-15 15:05:52 -0800 |
commit | f8796b4dce9202306dcd49afbdc9272f26845329 (patch) | |
tree | babc1be1d12a427950b802d5f2be814a7d2ed3c4 /find_java/find_java.bat | |
parent | adf24e024be5f87914ffd8575e4b744151eebdbe (diff) | |
download | sdk-f8796b4dce9202306dcd49afbdc9272f26845329.zip sdk-f8796b4dce9202306dcd49afbdc9272f26845329.tar.gz sdk-f8796b4dce9202306dcd49afbdc9272f26845329.tar.bz2 |
find_java.bat now uses env var instead of find
The officially recommended way to query an OS for its 32-bit/64-bit
architecture can be found in this KB article:
http://support.microsoft.com/kb/556009
Unfortunately, this fails for some subset of users for at least two
reasons:
1) Many users install Unix tools on their Windows box, overwriting
"find" with the Unix variant that doesn't support the \i parameter
2) Some machines are simply missing reg.exe. I've seen one claim in
the wild that this was due to an agressive anti-virus scanner
removing malware from their machine.
Therefore, we now use absolute paths to the utilities we want to
target. Additionally, we now have fallback handling if reg.exe is
missing, where we, instead, rely on the %PROCESSOR_ARCHITECTURE%
environment variable.
Related issues:
https://code.google.com/p/android/issues/detail?id=82099
https://code.google.com/p/android/issues/detail?id=82388
Change-Id: Icee0882fa6e1f5359c086498eb2679197cdf6f8e
Diffstat (limited to 'find_java/find_java.bat')
-rwxr-xr-x | find_java/find_java.bat | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/find_java/find_java.bat b/find_java/find_java.bat index b0bb165..01367c1 100755 --- a/find_java/find_java.bat +++ b/find_java/find_java.bat @@ -22,9 +22,21 @@ rem Command-line reference: rem http://technet.microsoft.com/en-us/library/bb490890.aspx
rem Query whether this system is 32-bit or 64-bit
-rem See also: http://stackoverflow.com/a/24590583/1299302
-reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" |^
-find /i "x86" > NUL && set arch_ext=32|| set arch_ext=64
+rem Note: Some users report that reg.exe is missing on their machine, so we
+rem check for that first, as we'd like to use it if we can.
+set sys_32=%SYSTEMROOT%\system32
+if exist %sys_32%\reg.exe (
+ rem This first-pass solution returns the correct architecture even if you
+ rem call this .bat file from a 32-bit process.
+ rem See also: http://stackoverflow.com/a/24590583/1299302
+ %sys_32%\reg query "HKLM\Hardware\Description\System\CentralProcessor\0"^
+ | %sys_32%\find /i "x86" > NUL && set arch_ext=32|| set arch_ext=64
+) else (
+ rem This fallback approach is simpler, but may misreport your architecture as
+ rem 32-bit if running from a 32-bit process. Still, it should serve to help
+ rem our users without reg.exe, at least.
+ if "%PROCESSOR_ARCHITECTURE%" == "x86" (set arch_ext=32) else (set arch_ext=64)
+)
rem Check we have a valid Java.exe in the path. The return code will
rem be 0 if the command worked or 1 if the exec failed (program not found).
|