Determine OS bit version with ruby

Determine OS bit version with ruby

Postby Pout » Wed Apr 20, 2011 10:32 am

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 bit

Is there another way?

Thx!
0

Pout 
 

Re: Determine OS bit version with ruby

Postby tbd » Wed Apr 20, 2011 12:24 pm

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
0
SketchUp Ruby Consultant | Podium 1.x developer
http://plugins.ro
User avatar
tbd 
 

Re: Determine OS bit version with ruby

Postby Dan Rathbun » Sat Apr 23, 2011 7:50 pm

Code: Select all
# 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.
0
    I have disengaged from all SketchUp public forums and will no longer see any replies. But direct PMs will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Determine OS bit version with ruby

    Postby Pout » Tue Apr 26, 2011 8:30 am

    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.
    0

    Pout 
     

    Re: Determine OS bit version with ruby

    Postby tbd » Tue Apr 26, 2011 8:39 am

    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"
    0
    SketchUp Ruby Consultant | Podium 1.x developer
    http://plugins.ro
    User avatar
    tbd 
     

    Re: Determine OS bit version with ruby

    Postby thomthom » Tue Apr 26, 2011 9:24 am

    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.
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: Determine OS bit version with ruby

    Postby Dan Rathbun » Tue Apr 26, 2011 7:19 pm

    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:

    Code: Select all
    if ENV.has_key?('ProgramFiles(x86)') &&
       File.exist?(ENV['ProgramFiles(x86)']) &&
       File.directory?(['ProgramFiles(x86)'])
      # safe to access directory
    end
    0
      I have disengaged from all SketchUp public forums and will no longer see any replies. But direct PMs will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: Determine OS bit version with ruby

      Postby Dan Rathbun » Tue Apr 26, 2011 7:28 pm

      TBD wrote: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.
      0
        I have disengaged from all SketchUp public forums and will no longer see any replies. But direct PMs will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago



        Ad Machine 
        Robot
         



         

        Return to Developers' Forum

        Who is online

        Users browsing this forum: driven and 2 guests

        Visit our sponsors: