Manipulating Environment Variables
It is important to realize that environment variables are not a PV-WAVE feature, they are part of every UNIX and Windows process. Although they can serve as a form of global memory, it is best to avoid using them in that way. It is preferrable to use system variables and common blocks as global memory.
UNIX Environment Variables
Every UNIX process has an “environment”. The environment consists of “environment variables”, each of which has a string value associated with it. Some environment variables always exist, such as path, which tells the shell where to look for programs, or term which specifies the kind of terminal being used. You may add other environment variables at any time from an interactive shell, or you can add them to the file, such as the .login file, that is executed when you log in.
When a process is created, it is given a copy of the environment from its parent process. PV-WAVE is no exception to this; when started, it inherits a copy of its parent’s environment. The parent process to PV-WAVE is usually the interactive shell from which it was started. In turn, any child process created by PV-WAVE (such as those from the SPAWN procedure) inherits a copy of PV-WAVE’s current environment.
Environment variables should be used for communicating with child processes. For example, you can change the SHELL environment variable prior to calling SPAWN. SPAWN then uses the newly defined shell to run its process.
The following sections list the procedures and functions PV-WAVE provides for manipulating the UNIX environment. For more information on these procedures and functions, see the PV‑WAVE Reference.
Windows Environment Variables
Environment variables define particular characteristics of your operating system environment, such as important directory paths. For example, when PV-WAVE is installed, several environment variables are automatically defined, such as the %RW_DIR% variable, which points to the main directory where Rogue Wave’s products are installed.
Whenever a process is created, it is given a copy of the environment from its parent process. PV-WAVE is no exception to this; when started, it inherits a copy of its parent’s environment. The parent process to PV-WAVE is usually the Command window from which it was started. In turn, any child process created by PV-WAVE (such as those from the SPAWN procedure) inherits a copy of PV-WAVE’s current environment.
The following sections list the procedures and functions PV-WAVE provides for manipulating the environment variables. For more information on these procedures and functions, see the PV‑WAVE Reference.
SETENV: Adding a New Environment Variable
The SETENV procedure adds a new environment variable, or changes the value of an existing environment variable, in the PV-WAVE process. It has the form:
SETENV, environment_expression
where environment_expression is a scalar string containing an environment expression to be added to the environment.
UNIX Example
For example, you can change the shell used by SPAWN by changing the value of the SHELL environment variable. A statement to change to the Bourne shell /bin/sh is:
SETENV, 'SHELL=/bin/sh'
Windows Example
For example, to change the HOMEPATH environment variable to point to the directory D:\users\chris\utah_data:
SETENV, 'HOMEPATH=D:\users\chris\utah_data'
GETENV: Get Environment Variable’s Equivalence String
The GETENV function returns the value (equivalence string) of a specified environment variable. It has the form:
result = GETENV(name)
where name is the name of the environment variable for which the value is desired. If name does not exist in the environment, a null string is returned.
UNIX Example
For example, to determine the type of terminal being used, you can enter the statement:
PRINT, 'The terminal type is:', GETENV('TERM')
Executing this statement on a Sun workstation gives the result:
The terminal type is: sun
Windows Example
For example, to determine value of the HOMEPATH variable, you can enter the statement:
PRINT, 'The value of HOMEPATH is:', GETENV('HOMEPATH')
Executing this statement gives the result:
The value of HOMEPATH is: D:\users\chris
ENVIRONMENT: Get Values of All Environment Variables
The ENVIRONMENT function returns a string array containing the values (equivalence strings) of all the environment variables currently found in the PV-WAVE process environment.
UNIX Example
The following statements print the entire environment, one environment variable per line:
; Get a copy of the environment.
WAVE> env = ENVIRONMENT()
; Print out, one variable per line.
WAVE> FOR I = 0, N_ELEMENTS(env)-1 DO PRINT, env(I)
Windows Example
The following statements print the entire environment, one environment variable per line:
; Get a copy of the environment.
WAVE> env = ENVIRONMENT()
; Print out, one variable per line.
WAVE> FOR I = 0, N_ELEMENTS(env)-1 DO PRINT, env(I)