Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Best way to determine if running on windows or unix-based system

Reply
Thread Tools

Best way to determine if running on windows or unix-based system

 
 
Carl Youngblood
Guest
Posts: n/a
 
      07-03-2004
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


 
Reply With Quote
 
 
 
 
Jamis Buck
Guest
Posts: n/a
 
      07-03-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
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))'


 
Reply With Quote
 
 
 
 
Erik Veenstra
Guest
Posts: n/a
 
      07-03-2004
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.

 
Reply With Quote
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      07-04-2004
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


 
Reply With Quote
 
Daniel Berger
Guest
Posts: n/a
 
      07-04-2004
Carl Youngblood <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>.. .
> 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
 
Reply With Quote
 
Carl Youngblood
Guest
Posts: n/a
 
      07-04-2004
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



 
Reply With Quote
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      07-04-2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a Ruby program determine whether it's running on a 32-bit or64-bit system? Eric Promislow Ruby 5 09-04-2008 01:27 PM
Best way to check that a process is running on a Unix system? Arthur Pemberton Python 1 05-29-2006 01:50 AM
Re: Best way to determine if a certain PID is still running Lars =?iso-8859-15?Q?Gust=E4bel?= Python 2 02-04-2006 01:04 AM
Best way to determine if a certain PID is still running David Hirschfield Python 3 02-03-2006 03:32 PM
what is the best way to determine system OS? googleboy Python 14 05-15-2005 12:51 PM



Advertisments