Retrieve the contents of a DOS environment variable.
XSharp.Core (in XSharp.Core.dll) Version: 2.5
cEnvVariable AS STRING
) AS STRING
public static string GetEnv(
- Type: String
The name of the environment variable whose contents you want to retrieve. (Note that GetEnv() is not case-sensitive.)
The contents of the specified environment variable.
If the variable cannot be found, GetEnv() returns a NULL_STRING.
GetEnv() lets you retrieve information from the DOS environment into an application program. Typically, this is configuration information — including path names — that describe the location of files (database, index, label, or reports).
Note: Instead of using environment variables for configuring your application, you may want to consider using registry settings.
Empty return value:|
If you are certain that an environment variable exists and yet GetEnv() always returns a NULL_STRING, be sure there are no spaces between the environment variable name and the first character of the string assigned to it in the DOS SET command.
This example retrieves the current DOS path setting, making it the current X# path:
1cPath := GetEnv("PATH")
2SET PATH TO (cPath)
This example uses environment variables to configure the specific locations of files. When you set up a system, define environment variables that contain the location of various file types, like this:
In the configuration section of your application program, assign the contents of the environment variables to variables.
Then when you access a file, preface the reference with the path, as follows:
1cDdfDirectory := GetEnv("LOC_DBF")
2USE (cDdfDirectory + "invoices.dbf")