Is there a way to obtain the computer name using ruby?

Discussion in 'Ruby' started by Mike Johnson, Apr 15, 2008.

  1. Mike Johnson

    Mike Johnson Guest

    Hi, all

    I am using ruby with watir to make some small scripts. I want to obtain
    the name of the computer where my script is running from. Is there a
    way to obtain the computer name using ruby?

    Thanks
     
    Mike Johnson, Apr 15, 2008
    #1
    1. Advertisements

  2. Mike Johnson

    Glen Holcomb Guest

    [Note: parts of this message were removed to make it a legal post.]

    Socket.gethostname
     
    Glen Holcomb, Apr 15, 2008
    #2
    1. Advertisements

  3. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Mike Johnson wrote:
    | Hi, all
    |
    | I am using ruby with watir to make some small scripts. I want to obtain
    | the name of the computer where my script is running from. Is there a
    | way to obtain the computer name using ruby?
    |
    | Thanks

    Well, there's ENV['USERDOMAIN'], and ENV['LOGONSERVER'], taken from the
    environment variables.

    Those might not be useful in an LDAP / Active directory environment,
    though. But then an LDAP gem should have an API to get the computer's name.

    - --
    Phillip Gawlowski
    Twitter: twitter.com/cynicalryan

    ~ Thank you. before I begin, I'd like everyone to notice that my report
    is in a professional, clear plastic binder...When a report looks this
    good, you know it'll get an A. That's a tip kids. Write it down. -- Calvin
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.8 (MingW32)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iEYEARECAAYFAkgFF/UACgkQbtAgaoJTgL+YmgCggd8DUvR4DK4sEk9QY5Ui5Ivo
    yo0AnR62VqtY1BLjbSzXnSeKDhs5Al2x
    =MXVE
    -----END PGP SIGNATURE-----
     
    Phillip Gawlowski, Apr 15, 2008
    #3
  4. Did not know that one, thid works too:

    ENV["COMPUTERNAME"]

    regards,

    Siep
     
    Siep Korteling, Apr 15, 2008
    #4
  5. Mike Johnson

    James Britt Guest


    name = `hostname`

    More or less.

    Don't recall if this works in Windows, but there should be something
    similar that returns machine info
     
    James Britt, Apr 15, 2008
    #5
  6. Mike Johnson

    Mike Johnson Guest

    Thank you Glen! This is exactly what I want. :)
     
    Mike Johnson, Apr 15, 2008
    #6
  7. Mike Johnson

    Mike Johnson Guest

    Thanks all for helping me!
     
    Mike Johnson, Apr 15, 2008
    #7
  8. I would discourage using this approach as it is very error prone and not
    portable.

    Kind regards

    robert
     
    Robert Klemme, Apr 15, 2008
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.