Narayan Iyer
Narayan Iyer

Reputation: 1

Accessing environment variables of another machine in Ruby

I am writing ruby script which accesses folders on other networked machines (windows). I need to know the environment variables on that machine, how do I do this? Once I get access to the remote environment variables, It will help me know where the software has been installed.

Thanks N.I

Upvotes: 0

Views: 2679

Answers (3)

D.Shawley
D.Shawley

Reputation: 59563

I would recommend the ruby WMI interface. As long as you have a fairly modern Windows (XP and up IIRC), you can fetch environment variables from remote machines easily. Google for more information.

Upvotes: 0

Phil Ross
Phil Ross

Reputation: 26100

Does your solution need to be pure Ruby? If not, you could use the PsExec command. The following will output the environment variables on remote (for the current user):

psexec \\remote cmd /C set

This works by executing cmd remotely and passing it the command set to run.

The following Ruby code will run PsExec and return the remote environment variables as a Hash:

Hash[*`psexec \\\\remote cmd /C set`.split("\n").
  collect {|i| i.split('=', 2)}.flatten]

Upvotes: 2

UncleMiF
UncleMiF

Reputation: 1171

You need to deploy simple HTTP-server with helper script that print to the output stream information you need (i.e environment variables, etc). Next you have to call that script from remote machine, and parse results.

Or, without server, add scheduled task to your remote machine, that writes once per day required information to some known file (I mean to file at fixed path). It's much simpler, however you'll see delayed information changes.

Upvotes: 0

Related Questions