[jruby-user] how to tell if you're on windows

2 views
Skip to first unread message

Roger Pack

unread,
Oct 10, 2009, 7:43:19 PM10/10/09
to us...@jruby.codehaus.org
Is it possible to tell that you're on windows from within jruby?
Thanks!
-r
--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Jay McGaffigan

unread,
Oct 10, 2009, 7:55:27 PM10/10/09
to us...@jruby.codehaus.org
I've used this :
require 'rubygems'
puts RbConfig::CONFIG['host_os']


then to check it:
if RbConfig::CONFIG['host_os'] =~ /mswin32/

Roger Pack

unread,
Oct 10, 2009, 8:22:11 PM10/10/09
to us...@jruby.codehaus.org

> then to check it:
> if RbConfig::CONFIG['host_os'] =~ /mswin32/

Thanks.

Stephen Bannasch

unread,
Oct 10, 2009, 10:24:17 PM10/10/09
to us...@jruby.codehaus.org
At 2:22 AM +0200 10/11/09, Roger Pack wrote:
> > then to check it:
> > if RbConfig::CONFIG['host_os'] =~ /mswin32/
>

fyi: you don't need to use rubgems, RbConfig::CONFIG is part of Ruby itself.

Charles Oliver Nutter

unread,
Oct 11, 2009, 12:46:11 AM10/11/09
to us...@jruby.codehaus.org
On Sat, Oct 10, 2009 at 5:55 PM, Jay McGaffigan <hooli...@gmail.com> wrote:
> I've used this :
> require 'rubygems'

Just require 'rbconfig'

> puts RbConfig::CONFIG['host_os']
>
>
> then to check it:
> if RbConfig::CONFIG['host_os'] =~ /mswin32/

- Charlie

Vladimir Sizikov

unread,
Oct 11, 2009, 3:21:38 AM10/11/09
to us...@jruby.codehaus.org
On Sun, Oct 11, 2009 at 4:24 AM, Stephen Bannasch
<stephen....@deanbrook.org> wrote:
> At 2:22 AM +0200 10/11/09, Roger Pack wrote:
>> > then to check it:
>> > if RbConfig::CONFIG['host_os'] =~ /mswin32/
>>
>
> fyi: you don't need to use rubgems, RbConfig::CONFIG is part of Ruby itself.

Indeed, and here's what we do in JRuby tests to detect Windows platform:

require 'rbconfig'
WINDOWS = Config::CONFIG['host_os'] =~ /Windows|mswin/

The 'Windows' part of the regexp sees to be a legacy for older JRuby
versions. With newer JRubys (JRubies?) checking for mswin seems to be
enough.

Thanks,
--Vladimir

Jesús García Sáez

unread,
Oct 11, 2009, 2:47:01 PM10/11/09
to us...@jruby.codehaus.org

I normally have this method in Kernel module (so it'll be globally available)

def is_windows?
!! if PLATFORM.match /java/
java.lang.System.getProperty('os.name').match(/win/i)
else
PLATFORM.match(/win/)
end
end

Roger Pack

unread,
Oct 12, 2009, 11:38:18 AM10/12/09
to us...@jruby.codehaus.org
Vladimir Sizikov wrote:
> On Sun, Oct 11, 2009 at 4:24 AM, Stephen Bannasch
> <stephen....@deanbrook.org> wrote:
>> At 2:22 AM +0200 10/11/09, Roger Pack wrote:
>>> > then to check it:
>>> > if RbConfig::CONFIG['host_os'] =~ /mswin32/
>>>
>>
>> fyi: you don't need to use rubgems, RbConfig::CONFIG is part of Ruby itself.
>
> Indeed, and here's what we do in JRuby tests to detect Windows platform:
>
> require 'rbconfig'
> WINDOWS = Config::CONFIG['host_os'] =~ /Windows|mswin/


As a note, it appears that many of the regexes in this thread don't
handle mingw32 (which is what the next release of windows one click
installer will be using).
Cheers!

---------------------------------------------------------------------

Charles Oliver Nutter

unread,
Oct 12, 2009, 1:12:31 PM10/12/09
to us...@jruby.codehaus.org
On Mon, Oct 12, 2009 at 9:38 AM, Roger Pack <li...@ruby-forum.com> wrote:
> As a note, it appears that many of the regexes in this thread don't
> handle mingw32 (which is what the next release of windows one click
> installer will be using).

I would strongly recommend that the one-click installer not introduce
a new platform name. FileUtils, for example, has special-cased logic
for mswin32. There are other examples as well. Is Luis Lavena in
charge of one-click these days?

- Charlie

Roger Pack

unread,
Oct 12, 2009, 3:01:20 PM10/12/09
to us...@jruby.codehaus.org
> I would strongly recommend that the one-click installer not introduce
> a new platform name. FileUtils, for example, has special-cased logic
> for mswin32. There are other examples as well. Is Luis Lavena in
> charge of one-click these days?

He is.
rubyinstaller.org

Unfortunately it's not really luis' thing--well...it kind of was to
decide to shift compilers, but that's another story.
RUBY_PLATFORM is set to mingw whether we want it to be or not :)

-r

Jon

unread,
Oct 13, 2009, 10:04:56 AM10/13/09
to us...@jruby.codehaus.org
> > I would strongly recommend that the one-click installer not introduce
> > a new platform name. FileUtils, for example, has special-cased logic
> > for mswin32. There are other examples as well. Is Luis Lavena in
> > charge of one-click these days?
>
> He is.
> rubyinstaller.org
>
> Unfortunately it's not really luis' thing--well...it kind of was to
> decide to shift compilers, but that's another story.
> RUBY_PLATFORM is set to mingw whether we want it to be or not :)
>
> -r


To make sure I didn't miss something here, is this

require 'rbconfig'
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/

viewed as not-good-enough-for-now when trying to determine if you're running on Windows from multiple Ruby impl's?

It appears to work for me on 1.9.1p243 from http://rubyinstaller.org/, JRuby 1.3.1, and IronRuby 0.9.1.

Jon

Roger Pack

unread,
Oct 13, 2009, 10:53:12 AM10/13/09
to us...@jruby.codehaus.org

> require 'rbconfig'
> RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
>
> viewed as not-good-enough-for-now when trying to determine if you're
> running on Windows from multiple Ruby impl's?
>
> It appears to work for me on 1.9.1p243 from http://rubyinstaller.org/,
> JRuby 1.3.1, and IronRuby 0.9.1.

I think that will work as long as you have Jruby versions new enough
[older versions wouldn't work--but who uses older versions anyway?]

---------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages