HP OpenVMS Systems

ask the wizard
Content starts here

getenv, setenv, symbols and logical names?

» close window

The Question is:

I am using the getenv() and setenv() functions to retrieve and set a logical.
When I first use getenv() to get the current value eveything is fine.
Then when I call setenv with overwrite set to 1 - it returns success (0) and
 subsequent calls to getenv() shows the logical to be zero. On exiting the
 program the logical remains unchanged.
Please clarify !!??

The Answer is :

  The C calls are emulating the behaviour of C found on UNIX, as is
  expected here.  Further, UNIX provides environment variables -- the
  closest analog on OpenVMS being a DCL symbol -- and not logical names.
  While the getenv call does work as a mechanism to retrieve either a
  logical name or a symbol, it maintains an internal cache of values
  for use with setenv and later getenv calls.  setenv does not write
  nor create DCL symbols nor OpenVMS logical names.
  This is consistent with the documented UNIX behavior.  The setenv call
  on UNIX does not change or create any symbols that will be visible in
  in the shell after the program exits.
  The OpenVMS Wizard would tend to encourage the use of lib$set_logical
  and of lib$get_logical for this application, and lib$set_symbol and of
  lib$get_symbol for DCL symbols.

answer written or last revised on ( 22-OCT-2002 )

» close window