getEnvironmentVariable: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{MacroFunction |name= getEnvironmentVariable |trusted=true |version=1.5.0 |description=Retrieves an operating system environment variable as a string. This function is usefu...") |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 9: | Line 9: | ||
{{Caution|This function is considered experimental and its implementation and parameters may change.}} | {{Caution|This function is considered experimental and its implementation and parameters may change.}} | ||
The '''Allow External Macro Access''' option | The '''Allow External Macro Access''' option on the Application tab of MapTool's Preferences must be enabled or this macro aborts with an error. | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
getEnvironmentVariable(varname) | getEnvironmentVariable(varname) | ||
</ | </syntaxhighlight> | ||
The value of {{code|varname}} specifies which environment variable is queried. On most operating systems, environment variables are all uppercase letters, but this is a naming convention and not required. Note that no way exists to query what all of the environment variables are, so the script writer must know which variable they want to retrieve. | The value of {{code|varname}} specifies which environment variable is queried. On most operating systems, environment variables are all uppercase letters, but this is a naming convention and not required. Note that no way exists to query what all of the environment variables are, so the script writer must know which variable they want to retrieve. | ||
Line 20: | Line 20: | ||
|example= | |example= | ||
You can use the following code to print the value of the PATH environment variable (which exists on most systems). Knowing the list of directories where an operating system searches for compiled executables could be considered a security vulnerability. See the above note about the '''Allow External Macro Access''' option. | You can use the following code to print the value of the PATH environment variable (which exists on most systems). Knowing the list of directories where an operating system searches for compiled executables could be considered a security vulnerability. See the above note about the '''Allow External Macro Access''' option. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[getEnvironmentVariable("PATH")] | [getEnvironmentVariable("PATH")] | ||
</ | [getEnvironmentVariable("TEMP")] | ||
[getEnvironmentVariable("USERNAME")] | |||
</syntaxhighlight> | |||
}} | }} | ||
[[Category:Miscellaneous Function]] | [[Category:Miscellaneous Function]] |
Latest revision as of 23:59, 14 March 2023
getEnvironmentVariable() Function
Note: This function can only be used in a Trusted Macro
• Introduced in version 1.5.0
Retrieves an operating system environment variable as a string.
The Allow External Macro Access option on the Application tab of MapTool's Preferences must be enabled or this macro aborts with an error.
This function is useful for situations where the script may wish to interact with the environment outside of MapTool, such as using the exportData() function to write a string to an external file.
Caution:
This function is considered experimental and its implementation and parameters may change.
Usage
getEnvironmentVariable(varname)
The value of varname
specifies which environment variable is queried. On most operating systems, environment variables are all uppercase letters, but this is a naming convention and not required. Note that no way exists to query what all of the environment variables are, so the script writer must know which variable they want to retrieve.
Example
You can use the following code to print the value of the PATH environment variable (which exists on most systems). Knowing the list of directories where an operating system searches for compiled executables could be considered a security vulnerability. See the above note about the Allow External Macro Access option.
[getEnvironmentVariable("PATH")]
[getEnvironmentVariable("TEMP")]
[getEnvironmentVariable("USERNAME")]