Zachary Scott
4/26/2008 12:46:00 AM
[Note: parts of this message were removed to make it a legal post.]
import os..
wait nvm >.<
On Fri, Apr 25, 2008 at 1:53 PM, Daniel Berger <djberg96@gmail.com> wrote:
>
>
> On Apr 25, 10:59 am, Kyle Hunter <keletmas...@gmail.com> wrote:
> > cb wrote:
> > > I need to execute commands differently based on the underlying
> > > platform. I don't need it down to the patch level or anything like
> > > that -- just basic stuff.
> >
> > > How do I test whether I'm runnnig on Windows, Linux, or Mac?
> >
> > > Thanks in advance.
> >
> > > CB
> >
> > if RUBY_PLATFORM =~ /linux/ then
> > #Linux Stuff
> > elsif RUBY_PLATFORM =~ /mswin32/ then
> > #Windows Stuff
> > end
>
> With other Ruby implementations out there this is no longer wise
> because Sun and Microsoft have hija^H^H^H^H co-opted the term
> 'platform'. If you check RUBY_PLATFORM with JRuby, for example, you'll
> get 'java'.
>
> If you need to check the underlying OS, use rbconfig.
>
> require 'rbconfig'
> include Config
>
> case CONFIG['host_os']
> when /mswin|windows/i
> # Windows
> when /linux/i
> # Linux
> when /sunos|solaris/i
> # Solaris
> else
> # Whatever
> end
>
> There's also the sys-uname library if you need more detailed
> information.
>
> Regards,
>
> Dan
>
>