Method: PSWindows::Exec#get_env_var

Defined in:
lib/beaker/host/pswindows/exec.rb

#get_env_var(key, clean = false) ⇒ Object

Return the value of a specific env var

Examples:

host.get_env_var('path')

Parameters:

  • key (String)

    The key to look for

  • clean (Boolean) (defaults to: false)

    Remove the ‘KEY=’ and only return the value of the env var



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/beaker/host/pswindows/exec.rb', line 123

def get_env_var key, clean = false
  self.close #refresh the state
  key = key.to_s.upcase
  val = exec(Beaker::Command.new("set #{key}"), :accept_all_exit_codes => true).stdout.chomp
  if val.empty?
    return ''
  else
    val = val.split(/\n/)[0] # only take the first result
    if clean
      val.gsub(/#{key}=/i,'')
    else
      val
    end
  end
end