Reading environment variables on the server via ColdFusion
I had the need to read in a environment variable off of the server via ColdFusion. Just replace the ENVIRONMENT_VARIABLE_ON_THE_SERVER with your own variable that you are going after.
<cfset system = CreateObject("java", "java.lang.System")>
<cfset environment = system.getenv()>
<cfset env = environment.get("ENVIRONMENT_VARIABLE_ON_THE_SERVER")>
<cfoutput>#env#</cfoutput>
<cfset environment = system.getenv()>
<cfset env = environment.get("ENVIRONMENT_VARIABLE_ON_THE_SERVER")>
<cfoutput>#env#</cfoutput>
This is based on some java code that I wrote up for a LCDS project.
public static String getEnvironment(String environmentVariableName) {
Map<String, String> env = System.getenv();
return env.get(environmentVariableName);
}
Map<String, String> env = System.getenv();
return env.get(environmentVariableName);
}
Comments
[Add Comment]
That's awesome. I was just cruising some very old code I wrote that does essentially the same thing via .NET, i think I was calling it with cfexecute as a command-line exe. Stupid of me to not think of Java at the time. Thanks.
# Posted By Nathan Strutz
| 1/23/12 3:48 PM
[Add Comment]