Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Best way to determine if running on windows or unix-based system (http://www.velocityreviews.com/forums/t815440-best-way-to-determine-if-running-on-windows-or-unix-based-system.html)

Carl Youngblood 07-03-2004 10:23 PM

Best way to determine if running on windows or unix-based system
 
I'm going to try using Ruby/DL to write a full-fledged ruby extension
for the curl library. I'd like it to work on both Windows and
Unix-based systems. I'm sure there are a lot of ways of doing this,
but what do you guys think is the best way to determine whether your
script is being called on a windows-based system or a unix-based
system?

Thanks,
Carl



Jamis Buck 07-03-2004 10:35 PM

Re: Best way to determine if running on windows or unix-based system
 
Carl Youngblood wrote:
> I'm going to try using Ruby/DL to write a full-fledged ruby extension
> for the curl library. I'd like it to work on both Windows and
> Unix-based systems. I'm sure there are a lot of ways of doing this,
> but what do you guys think is the best way to determine whether your
> script is being called on a windows-based system or a unix-based
> system?


There is a constant, RUBY_PLATFORM, which tells you this. On my system:

ruby -e "p RUBY_PLATFORM"
--> "i686-linux-gnu"

- Jamis

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis

ruby -ropenssl
-e'k="01234567";p((c,c.padding,c.iv,c.key=OpenSSL:: Cipher::BF.new,0,k,k*2)[0].decrypt.update("1A81803C452C324619D319F980D5B84DB B45FC0FE2BAA045".scan(/../).map{|n|n.to_i(16).chr}.join))'



Erik Veenstra 07-03-2004 10:50 PM

Re: Best way to determine if running on windows or unix-based system
 
On Sun, 04 Jul 2004 07:23:21 +0900, Carl Youngblood wrote:

> I'm going to try using Ruby/DL to write a full-fledged ruby
> extension for the curl library. I'd like it to work on both
> Windows and Unix-based systems. I'm sure there are a lot of
> ways of doing this, but what do you guys think is the best
> way to determine whether your script is being called on a
> windows-based system or a unix-based system?


<code language="ruby">

require "rbconfig"

def linux?
not windows? and not cygwin?
end

def windows?
not (target_os.downcase =~ /32/).nil?
end

def cygwin?
not (target_os.downcase =~ /cyg/).nil?
end

def target_os
Config::CONFIG["target_os"] or ""
end

</code>

gegroet,
Erik V.


nobu.nokada@softhome.net 07-04-2004 01:03 AM

Re: Best way to determine if running on windows or unix-based system
 
Hi,

At Sun, 4 Jul 2004 07:23:21 +0900,
Carl Youngblood wrote in [ruby-talk:105192]:
> I'm going to try using Ruby/DL to write a full-fledged ruby extension
> for the curl library. I'd like it to work on both Windows and
> Unix-based systems. I'm sure there are a lot of ways of doing this,
> but what do you guys think is the best way to determine whether your
> script is being called on a windows-based system or a unix-based
> system?


It depends on what you want to know. For instance,

: file system
case File::ALT_SEPARATOR
when nil
p :unixen
when "\\";
p :dosish # mswin32, mingw32, bccwin32, djgpp or human68k ...
else
# unknown
end

: fork avaiability
begin
fork {}
true
rescue NotImplementedError
false
end

and mounts of different features.
What do you want to know about?

BTW, what do you mean by "ruby extension"? If you mean an
extension library written in C, you definitely don't need DL.
You can use HAVE_* macros in config.h.

--
Nobu Nakada



Daniel Berger 07-04-2004 02:29 AM

Re: Best way to determine if running on windows or unix-based system
 
Carl Youngblood <carl.youngblood@gmail.com> wrote in message news:<e5ed7b6904070315223f24e80e@mail.gmail.com>.. .
> I'm going to try using Ruby/DL to write a full-fledged ruby extension
> for the curl library. I'd like it to work on both Windows and
> Unix-based systems. I'm sure there are a lot of ways of doing this,
> but what do you guys think is the best way to determine whether your
> script is being called on a windows-based system or a unix-based
> system?
>
> Thanks,
> Carl


if File::ALT_SEPARATOR
# you're on Windows
else
# anything but Windows
end

Regards,

Dan

Carl Youngblood 07-04-2004 03:07 AM

Re: Best way to determine if running on windows or unix-based system
 
Okay, forgive me for my ignorance but I thought a "ruby extension"
meant taking some library that was written in C and making its
functionality accessible from within ruby. The thing is, I'd rather
not have to do any compiling or anything to install my extension. I'd
like to simply check that the required shared library is in the path,
grab it and create a ruby-style wrapper class for it without needing
to do any compiling. Is there a better way to do this than using
Ruby/DL?

> BTW, what do you mean by "ruby extension"? If you mean an
> extension library written in C, you definitely don't need DL.
> You can use HAVE_* macros in config.h.
>
> --
> Nobu Nakada




nobu.nokada@softhome.net 07-04-2004 03:49 AM

Re: Best way to determine if running on windows or unix-based system
 
Hi,

At Sun, 4 Jul 2004 12:07:13 +0900,
Carl Youngblood wrote in [ruby-talk:105201]:
> Okay, forgive me for my ignorance but I thought a "ruby extension"
> meant taking some library that was written in C and making its
> functionality accessible from within ruby. The thing is, I'd rather
> not have to do any compiling or anything to install my extension. I'd
> like to simply check that the required shared library is in the path,
> grab it and create a ruby-style wrapper class for it without needing
> to do any compiling. Is there a better way to do this than using
> Ruby/DL?


Well, I guess it would be possible but wouldn't be called
"extension library". We may need a new name.

--
Nobu Nakada




All times are GMT. The time now is 09:55 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.