Function Getenv() Foundation
Retrieves the contents of an operating system environment variable.
Getenv( <cSetVar> ) --> cString
Getenv() returns the contents of the specified OS environment variable as a character string. If the variable is not set, a null string ("") is returned.
The environment function Getenv() provides information about the operating system environment from within a program. Generally this information concerns the configuration. Getenv() is most frequently used for retrieving the path name which designates the path where the files accessed by an application program are found. This is especially advantageous in a network environment.
// The example uses the environment variable DBF_PATH as a
// path for DBF files. Before the start of a program this
// variable must be defined at the operating system level.
// For example: C:>SET DBF_PATH=c:\xpp\samples\data\misc
PROCEDURE SetDataPath()
LOCAL cPath := Getenv("DBF_PATH")
IF ! Empty(cPath)
SET PATH TO (cPath)
ELSE
? "Environment variable DBF_PATH is not defined"
ENDIF
RETURN
// In this example an environment variable is used to
// establish whether a LOGIN is permitted in a network
// environment. Access is denied when a file save is
// currently taking place.
PROCEDURE Login()
LOCAL cPath:=Getenv("DBF_PATH")
CLS
IF File(cPath+"\BACKUP.LOG")
? "The files are in the process of being saved."
? "Access is not possible at this time!"
QUIT
ENDIF
RETURN
PROCEDURE Backup()
LOCAL cPath:=Getenv("DBF_PATH"), nHandle
CLS
IF ( nHandle := FCreate(cPath+"BACKUP.LOG") ) > 0
FClose( nHandle )
? "Files are saved with a backup routine"
IF FErase( cPath+"BACKUP.LOG" ) == 0
? "Files are saved"
ENDIF
ELSE
? "File error:", FError()
ENDIF
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.