Determine OS bit version with ruby
-
Is there a way to determine wether the OS where Sketchup is installed on is 32 or 64 bit?
puts RUBY_PLATFORM gives me i386-mswin32 (which is probably the ruby version since i am working on 64 bit)machine_bytes = ['foo'].pack('p').size
machine_bits = machine_bytes * 8
Also gives me 32, again probably because ruby/SU is 32 bitIs there another way?
Thx!
-
why do you need that in the first place ?
for me (OSX), the ruby command
1.size
is- 4 -> 32 bit SU Ruby
- 8 -> 64 bit command line Ruby
on Windows you can check for GetSystemWow64Directory as it is not present on 32bit version
-
# define these methods within your module or class def is_windows_32bit? ( not is_windows_64bit? ) end def is_windows_64bit? ENV.has_key?('ProgramFiles(x86)') end
Note: ENV['PROCESSOR_ARCHITECTURE'] may return a label for a 64bit CPU (like "AMD64",) but still could have a 32bit Windows OS installed.
-
thx TBD and Dan
I need it to determine where certain file are located.
For now i have used a similuar aproach as Dan suggested in which you look if Program Files(x86) 'exists'
But i think his method is better. -
as I dont have 64bit Windows to test it up, take in account this as well - "The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit"
-
And some versions of Windows doesn't even have folders names "ProgramFiles" but instead a localized version. Hard coded paths are not reliable, they should be requested from the system.
-
The NAMES of the environment vars should NOT change, and their VALUES should be the localized language folder names.
So it is much safer to test FIRST if
ENV.has_key?
THEN use the value of the varible (IF it is present,) to check if the folder exists using:if ENV.has_key?('ProgramFiles(x86)') && File.exist?(ENV['ProgramFiles(x86)']) && File.directory?(['ProgramFiles(x86)']) # safe to access directory end
-
@unknownuser said:
as I dont have 64bit Windows to test it up, take in account this as well - "The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit"
%ProgramFiles% = ENV['ProgramFiles']
But I told him to use %ProgramFiles(x86)% (which is ENV['ProgramFiles(x86)'],) and should not be present on 32bit systems.
On a 64bit system, running a 32bit process (in this case 32bit Sketchup, running 32bit Ruby as a subprocess,) a copy of the enviroment is created for the process. Both the vars ENV['ProgramFiles'] and ENV['ProgramFiles(x86)'] should contain a pathstring that points at the same 32bit localized "program files" directory.
Advertisement