Foolproof way of determining host platform

Discussion in 'Ruby' started by Paul Mckibbin, Jan 15, 2010.

  1. Hi all,

    I am trying to work out a 'better' way of determing if my ruby code is
    running on a Windows platform, and so far I've had to modify the
    standard RUBY_PLATFORM several times depending on which version of
    windows/compiler etc. it was built with. I also tried using

    require 'rbconfig'
    Config::CONFIG['host_os']

    but found that (with 1.8.6) there are still distinction versions
    reported on windows, such as a mingw32 build reporting an os of
    'mingw32'.

    I came up with Config::CONFIG['EXEEXT'] to determine whether it is
    running on Windows as opposed to any other platform we support. Windows
    return ".exe" and other platforms tested come back with "", so that
    seems to work, but is there a better way?

    Best wishes,
    Mac
    --
    Posted via http://www.ruby-forum.com/.
    Paul Mckibbin, Jan 15, 2010
    #1
    1. Advertising

  2. On 15.01.2010 21:21, Paul Mckibbin wrote:

    > I came up with Config::CONFIG['EXEEXT'] to determine whether it is
    > running on Windows as opposed to any other platform we support. Windows
    > return ".exe" and other platforms tested come back with "", so that
    > seems to work, but is there a better way?


    You can give a binary any extension you like on *NIX, as long as you set
    "chmod +x /my/binary.whatever".

    --
    Phillip Gawlowski
    Phillip Gawlowski, Jan 15, 2010
    #2
    1. Advertising

  3. Paul Mckibbin

    Luis Lavena Guest

    On Jan 15, 5:21 pm, Paul Mckibbin <> wrote:
    > Hi all,
    >
    > I am trying to work out a 'better' way of determing if my ruby code is
    > running on a Windows platform, and so far I've had to modify the
    > standard RUBY_PLATFORM several times depending on which version of
    > windows/compiler etc. it was built with. I also tried using
    >
    > require 'rbconfig'
    > Config::CONFIG['host_os']
    >
    > but found that (with 1.8.6) there are still distinction versions
    > reported on windows, such as a mingw32 build reporting an os of
    > 'mingw32'.
    >


    That is because is not the OS, but also the C Runtime used to link to
    Ruby and the tools to built it.

    MinGW == GCC and mswin32 for VC6

    Also mswin32_80 for VS2008

    And you also have cygwin and other compilers.

    > I came up with Config::CONFIG['EXEEXT'] to determine whether it is
    > running on Windows as opposed to any other platform we support. Windows
    > return ".exe" and other platforms tested come back with "", so that
    > seems to work, but is there a better way?


    host_os and evaluate /mswin|mingw/

    There is no perfect solution.

    --
    Luis Lavena
    Luis Lavena, Jan 15, 2010
    #3
  4. Aldric Giacomoni, Jan 15, 2010
    #4
  5. Paul Mckibbin

    Intransition Guest

    Other options:

    require 'rubygems'
    Gem::platform.local

    Shameless ripoff with some minor improvements:

    require 'facets/platform'
    Platform.local

    The OS gem looks promising.

    My question is why isn't something like this a standard part of Ruby?
    Intransition, Jan 15, 2010
    #5
  6. Thomas Sawyer wrote:
    > The OS gem looks promising.
    >
    > My question is why isn't something like this a standard part of Ruby?


    One word: Skynet.
    --
    Posted via http://www.ruby-forum.com/.
    Aldric Giacomoni, Jan 15, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. amit
    Replies:
    5
    Views:
    6,355
    MK Wong
    Oct 5, 2003
  2. Replies:
    0
    Views:
    313
  3. Chris Rebert
    Replies:
    3
    Views:
    287
    Chris Rebert
    Apr 13, 2010
  4. Brian Mac
    Replies:
    0
    Views:
    126
    Brian Mac
    Apr 1, 2008
  5. Replies:
    4
    Views:
    243
    Arne Vajh?j
    Apr 4, 2013
Loading...

Share This Page