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

Discussion in 'Ruby' started by Carl Youngblood, Jul 3, 2004.

  1. 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
     
    Carl Youngblood, Jul 3, 2004
    #1
    1. Advertising

  2. Carl Youngblood

    Jamis Buck Guest

    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.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))'
     
    Jamis Buck, Jul 3, 2004
    #2
    1. Advertising

  3. 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.
     
    Erik Veenstra, Jul 3, 2004
    #3
  4. Carl Youngblood

    Guest

    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
     
    , Jul 4, 2004
    #4
  5. Carl Youngblood <> wrote in message news:<>...
    > 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
     
    Daniel Berger, Jul 4, 2004
    #5
  6. 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
     
    Carl Youngblood, Jul 4, 2004
    #6
  7. Carl Youngblood

    Guest

    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
     
    , Jul 4, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Hirschfield
    Replies:
    3
    Views:
    3,300
    Thomas Guettler
    Feb 3, 2006
  2. Lars =?iso-8859-15?Q?Gust=E4bel?=

    Re: Best way to determine if a certain PID is still running

    Lars =?iso-8859-15?Q?Gust=E4bel?=, Feb 3, 2006, in forum: Python
    Replies:
    2
    Views:
    456
    MrJean1
    Feb 4, 2006
  3. Arthur Pemberton
    Replies:
    1
    Views:
    367
    Eriol
    May 29, 2006
  4. =?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=

    Re: Best way to check that a process is running on a Unix system?

    =?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=, May 28, 2006, in forum: Python
    Replies:
    1
    Views:
    5,192
    Nick Craig-Wood
    Jun 5, 2006
  5. markus
    Replies:
    22
    Views:
    674
    Dances With Crows
    Sep 22, 2004
Loading...

Share This Page