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);
}
<cfset system = CreateObject("java", "java.lang.System")>
<cfset environment = system.getenv()>
<cfset env = environment.get("PATH")>
<cfoutput>#env#</cfoutput>