How do I tell when I'm on Cygwin?

HighLine has some code like this:

   begin
     require "Win32API"

     if # I'm looking for the line that goes right here (see below).
       raise LoadError, "On Cygwin, not pure Windows."
     end

     # assume we're on Windows here...
   rescue LoadError
     # assume we're on a Posix OS here...
   end

The problem is that Cygwin is using the Windows code and the Posix code would be a better choice there. What's a test I can use to detect Cygwin in this scenario?

James Edward Gray II

posix = Process.fork{} and Process.wait rescue nil

-a

···

On Wed, 25 Oct 2006, James Edward Gray II wrote:

HighLine has some code like this:

begin
   require "Win32API"

   if # I'm looking for the line that goes right here (see below).
     raise LoadError, "On Cygwin, not pure Windows."
   end

   # assume we're on Windows here...
rescue LoadError
   # assume we're on a Posix OS here...
end

The problem is that Cygwin is using the Windows code and the Posix code would be a better choice there. What's a test I can use to detect Cygwin in this scenario?

James Edward Gray II

--
my religion is very simple. my religion is kindness. -- the dalai lama

I /think/ RUBY_PLATFORM is different for cygwin than the pure windows
version, but I don't have a cygwin install nearby to confirm. Perhaps

    unless RUBY_PLATFORM =~ /mswin/
      raise LoadError, "..."
    end

would work?

Cheers,
/Nick

···

On 10/24/06, James Edward Gray II <james@grayproductions.net> wrote:

HighLine has some code like this:

   begin
     require "Win32API"

     if # I'm looking for the line that goes right here (see below).
       raise LoadError, "On Cygwin, not pure Windows."
     end

     # assume we're on Windows here...
   rescue LoadError
     # assume we're on a Posix OS here...
   end

The problem is that Cygwin is using the Windows code and the Posix
code would be a better choice there. What's a test I can use to
detect Cygwin in this scenario?

Everyone, please remember that Ara is kidding about this. Please do
not let this become an idiom.
The fact that the Win32 version of Ruby doesn't support fork is a
temporary and unfortunate implementation detail, not something you can
rely on.

···

On 10/24/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:

On Wed, 25 Oct 2006, James Edward Gray II wrote:

> HighLine has some code like this:
>
> begin
> require "Win32API"
>
> if # I'm looking for the line that goes right here (see below).
> raise LoadError, "On Cygwin, not pure Windows."
> end
>
> # assume we're on Windows here...
> rescue LoadError
> # assume we're on a Posix OS here...
> end
>
> The problem is that Cygwin is using the Windows code and the Posix code would
> be a better choice there. What's a test I can use to detect Cygwin in this
> scenario?
>
> James Edward Gray II

   posix = Process.fork{} and Process.wait rescue nil

Via One click installer in regular windows:

irb(main):001:0> RUBY_PLATFORM
=> "i386-mswin32"

On CYGWIN:

irb(main):001:0> RUBY_PLATFORM
=> "i386-cygwin"

···

On 10/24/06, Nick Sieger <nicksieger@gmail.com> wrote:

I /think/ RUBY_PLATFORM is different for cygwin than the pure windows
version, but I don't have a cygwin install nearby to confirm. Perhaps

you are spoiling all the fun!

:wink:

-a

···

On Wed, 25 Oct 2006, Wilson Bilkovich wrote:

Everyone, please remember that Ara is kidding about this. Please do not let
this become an idiom. The fact that the Win32 version of Ruby doesn't
support fork is a temporary and unfortunate implementation detail, not
something you can rely on.

--
my religion is very simple. my religion is kindness. -- the dalai lama

It seems safer to target this one as an exception, rather than mswin, so I'll go with that.

One last question though, if Termios was installed for Cygwin would it work OK there? I'm trying to figure out if I need to bypass HighLine's search for that too.

Thanks for the help all.

James Edward Gray II

···

On Oct 24, 2006, at 1:40 PM, Gregory Brown wrote:

irb(main):001:0> RUBY_PLATFORM
=> "i386-cygwin"

It's easier even than that ... just look up. If Austin Ziegler is
sneering at you, you're on CygWin.

<ducking>

···

ara.t.howard@noaa.gov wrote:

On Wed, 25 Oct 2006, Wilson Bilkovich wrote:

Everyone, please remember that Ara is kidding about this. Please do
not let
this become an idiom. The fact that the Win32 version of Ruby doesn't
support fork is a temporary and unfortunate implementation detail, not
something you can rely on.

you are spoiling all the fun!

:wink:

-a

I have no idea how to install termios for Cygwin since it's not part
of the standard distribution (i don't think), and I'm not really a
Cygwin user.

However, stty is included with Cygwin, so I think highline would work
using that.

···

On 10/24/06, James Edward Gray II <james@grayproductions.net> wrote:

On Oct 24, 2006, at 1:40 PM, Gregory Brown wrote:

> irb(main):001:0> RUBY_PLATFORM
> => "i386-cygwin"

It seems safer to target this one as an exception, rather than mswin,
so I'll go with that.

One last question though, if Termios was installed for Cygwin would
it work OK there? I'm trying to figure out if I need to bypass
HighLine's search for that too.

But that's not true. You can get an identical scenario if you browse to:
shootout.alioth.debian.org :slight_smile:

···

On 10/24/06, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

It's easier even than that ... just look up. If Austin Ziegler is
sneering at you, you're on CygWin.

Gregory Brown wrote:

···

On 10/24/06, James Edward Gray II <james@grayproductions.net> wrote:

On Oct 24, 2006, at 1:40 PM, Gregory Brown wrote:

> irb(main):001:0> RUBY_PLATFORM
> => "i386-cygwin"

It seems safer to target this one as an exception, rather than mswin,
so I'll go with that.

One last question though, if Termios was installed for Cygwin would
it work OK there? I'm trying to figure out if I need to bypass
HighLine's search for that too.

I have no idea how to install termios for Cygwin since it's not part
of the standard distribution (i don't think), and I'm not really a
Cygwin user.

However, stty is included with Cygwin, so I think highline would work
using that.

Just about anything that will compile and execute on Linux will compile
and execute on CygWin. However, since the Ruby community has deprecated
CygWin, I'm not sure why new code should do other than detect it and
complain. :slight_smile:

When I run software on a Windows machine, my preference is for native
tools, with CygWin a "plan B" and a Gentoo virtual machine as "plan C".

Well, if it's not installed HighLine won't find it anyway. Another post claimed most Unix stuff will compile, so if someone manages it, we will find it normally.

I'll try bypassing just the native Windows check and see if that's enough.

Thanks for all the help everyone!

James Edward Gray II

···

On Oct 24, 2006, at 7:40 PM, Gregory Brown wrote:

On 10/24/06, James Edward Gray II <james@grayproductions.net> wrote:

On Oct 24, 2006, at 1:40 PM, Gregory Brown wrote:

> irb(main):001:0> RUBY_PLATFORM
> => "i386-cygwin"

It seems safer to target this one as an exception, rather than mswin,
so I'll go with that.

One last question though, if Termios was installed for Cygwin would
it work OK there? I'm trying to figure out if I need to bypass
HighLine's search for that too.

I have no idea how to install termios for Cygwin since it's not part
of the standard distribution (i don't think), and I'm not really a
Cygwin user.

However, stty is included with Cygwin, so I think highline would work
using that.

hi ed - what exactly do you mean by that?

-a

···

On Wed, 25 Oct 2006, M. Edward (Ed) Borasky wrote:

However, since the Ruby community has deprecated
CygWin, I'm not sure why new code should do other than detect it and
complain. :slight_smile:

--
my religion is very simple. my religion is kindness. -- the dalai lama

I'm not sure ... I just know every time I mention that I like CygWin
here, I get yelled at. :slight_smile:

···

ara.t.howard@noaa.gov wrote:

On Wed, 25 Oct 2006, M. Edward (Ed) Borasky wrote:

However, since the Ruby community has deprecated
CygWin, I'm not sure why new code should do other than detect it and
complain. :slight_smile:

hi ed - what exactly do you mean by that?

-a

Hey, SHUT UP! :wink:

I think it's just that One-Click installer is the preferred method and
is better supported. The philosophical arguments about Cygwin aside,
of course.

···

On 10/24/06, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

I'm not sure ... I just know every time I mention that I like CygWin
here, I get yelled at. :slight_smile:

The only real reason not to use it that I'm aware of is that it is fairly slow.
Of course, the native Ruby on Win32 is 10x slower than on Linux for
many tasks, so maybe that's not much of a selling point.

···

On 10/24/06, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

ara.t.howard@noaa.gov wrote:
> On Wed, 25 Oct 2006, M. Edward (Ed) Borasky wrote:
>
>> However, since the Ruby community has deprecated
>> CygWin, I'm not sure why new code should do other than detect it and
>> complain. :slight_smile:
>
> hi ed - what exactly do you mean by that?
>
> -a
I'm not sure ... I just know every time I mention that I like CygWin
here, I get yelled at. :slight_smile:

Wilson Bilkovich wrote:

The only real reason not to use it that I'm aware of is that it is
fairly slow.
Of course, the native Ruby on Win32 is 10x slower than on Linux for
many tasks, so maybe that's not much of a selling point.

Really? Curt, Austin? Is native (one-click) Ruby 1.8.5 slower on, say, a
933 MHz Pentium III running Windows than, say, a gcc-compiled (O2) Ruby
on the same hardware?

Let me drag out my matrix benchmark and dual-booted (Win XP and Gentoo
Linux) Athlon XP laptop and see for myself!

Be back later, as they say in IRC!

I've found this true before. The Cygwin version simply performs better by a
significant margin than the one-click.

I will run some benchmarks again and post as well, as I don't have the old
figures handy.

···

On 10/24/06, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

Really? Curt, Austin? Is native (one-click) Ruby 1.8.5 slower on, say, a
933 MHz Pentium III running Windows than, say, a gcc-compiled (O2) Ruby
on the same hardware?

--
Robert W. Oliver II
President, OCS Solutions, Inc. - Web Hosting and Development

Toll-Free Phone - 1-800-672-8415

OCS Ruby Forums - http://www.rubyforums.com/
My Blog - http://www.rwoliver.com/

This is mostly because we're not using the latest compiler. That's one
reason I've been pushing so hard for the use of MSVC8 instead of
MSVC6. A MinGW compile is about 5 - 10% faster than the current MSVC6
(because even the slightly older GCC 3.x is a better compiler than the
many-years-old MSVC6). An MSVC8 compile would be up to 30% faster,
IIRC. I'd have to do some benchmarking, but I'm not on a Windows
machine with that right now.

-austin

···

On 10/24/06, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

Wilson Bilkovich wrote:
> The only real reason not to use it that I'm aware of is that it is
> fairly slow.
> Of course, the native Ruby on Win32 is 10x slower than on Linux for
> many tasks, so maybe that's not much of a selling point.
Really? Curt, Austin? Is native (one-click) Ruby 1.8.5 slower on, say, a
933 MHz Pentium III running Windows than, say, a gcc-compiled (O2) Ruby
on the same hardware?

--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * You are in a maze of twisty little passages, all alike. // halo • statue
               * austin@zieglers.ca

M. Edward (Ed) Borasky wrote:

Wilson Bilkovich wrote:

The only real reason not to use it that I'm aware of is that it is
fairly slow.
Of course, the native Ruby on Win32 is 10x slower than on Linux for
many tasks, so maybe that's not much of a selling point.

Really? Curt, Austin? Is native (one-click) Ruby 1.8.5 slower on, say, a
933 MHz Pentium III running Windows than, say, a gcc-compiled (O2) Ruby
on the same hardware?

Let me drag out my matrix benchmark and dual-booted (Win XP and Gentoo
Linux) Athlon XP laptop and see for myself!

Be back later, as they say in IRC!

OK ... here we go. I actually had to re-install CygWin; I had deleted it
because I wasn't using Windows on my laptop. By the way, speaking of
laptops, I want all of you at RubyConf to know that it has gotten over
the sadness it was feeling as a dual-booted Window and Linux machine
being surrounded by Macs.

From

http://rubyforge.org/cgi-bin/viewvc.cgi/MatrixBenchmark/athlon-xp-2000.log?root=cougar&view=co

A brief test of three Ruby implementations on the same processor. First, the
processor specifications (Linux "/proc/cpuinfo"):

processor : 0
vendor_id : AuthenticAMD
cpu family : 6
model : 8
model name : mobile AMD Athlon(tm) XP 2000+
stepping : 1
cpu MHz : 1656.440
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 mmx fxsr sse syscall mp mmxext 3dnowext 3dnow ts fid vid
bogomips : 3313.62

Now, the times.

Native Windows One-Click Ruby Installer:
ruby 1.8.5 (2006-08-25) [i386-mswin32]
Matrix of dimension 256 times its inverse = identity? true
137.658000 0.060000 137.718000 (137.719000)

CygWin Ruby:
ruby 1.8.5 (2006-08-25) [i386-cygwin]
Matrix of dimension 256 times its inverse = identity? true
137.598000 0.110000 137.708000 (137.768000)

Gentoo Linux Ruby
Compiled from source with GCC 4.1.1 -O2 -march=athlon-xp -fomit-frame-pointer
ruby 1.8.5 (2006-08-25) [i686-linux]
Matrix of dimension 256 times its inverse = identity? true
107.380000 0.010000 107.390000 (107.425632)

So, it appears that on this benchmark, the One-Click and CygWin
interpreters are equal!! But GCC 4.1.1 beat them both.

Back to RAMEAU. :slight_smile: