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

  • Thread starter Carl Youngblood
  • Start date
C

Carl Youngblood

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
 
J

Jamis Buck

Carl said:
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
(e-mail address 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("1A81803C452C324619D319F980D5B84DBB45FC0FE2BAA045".scan(/../).map{|n|n.to_i(16).chr}.join))'
 
E

Erik Veenstra

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.
 
N

nobu.nokada

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.
 
D

Daniel Berger

Carl Youngblood said:
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
 
C

Carl Youngblood

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?
 
N

nobu.nokada

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top