Task

Show how to get one of your process's environment variables.

The available variables vary by system;   some of the common ones available on Unix include:

   PATH
   HOME
   USER


/* NetRexx */
options replace format comments java crossref symbols nobinary
 
runSample(arg)
return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method sysEnvironment(vn = '') public static
  if vn.length > 0 then do
    envName = vn
    envValu = System.getenv(envName)
    if envValu = null then envValu = ''
    say envName '=' envValu
    end
  else do
    envVars = System.getenv()
    key = String
    loop key over envVars.keySet()
      envName = key
      envValu = String envVars.get(key)
      say envName '=' envValu
      end key
    end
  return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method sysProperties(vn = '') public static
  if vn.length > 0 then do
    propName = vn
    propValu = System.getProperty(propName)
    if propValu = null then propValu = ''
    say propName '=' propValu
    end
  else do
    sysProps = System.getProperties()
    key = String
    loop key over sysProps.keySet()
      propName = key
      propValu = sysProps.getProperty(key)
      say propName '=' propValu
      end key
    end
  return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) public static
  parse arg ev pv .
  if ev = '' then ev = 'CLASSPATH'
  if pv = '' then pv = 'java.class.path'
  say '-'.left(80, '-').overlay(' Environment "'ev'" ', 5)
  sysEnvironment(ev)
  say '-'.left(80, '-').overlay(' Properties "'pv'" ', 5)
  sysProperties(pv)
  say
  say '-'.left(80, '-').overlay(' Environment ', 5)
  sysEnvironment()
  say '-'.left(80, '-').overlay(' Properties ', 5)
  sysProperties()
  say
  return
 