From: Daniel Berger Date: 2008-04-26T02:53:51+09:00 Subject: Re: determing what os is running On Apr 25, 10:59 am, Kyle Hunter 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