Mar 19
Environment Variables With ColdFusion
Posted by James Netherton | Monday 19 March 2007 8:26 PM | In ColdFusion
I came across this today by accident. I never knew that ColdFusion was able to pick up any environment variables that are set within the host operating system. Here's how I came across this behavior...
I was hacking together a sort algorithm and naughtily, for the purposes of being able to quickly see things working, I did not scope my variables. One of my variables was named temp. I started getting some freaky errors, you'll understand why if you run this code on a Windows system:
Which will produce something like "C:\windows\temp".
What's interesting is that the variable exists within the CGI variable scope. But, CFDUMP the CGI scope and they'll be no sign of a variable named "temp".
What's happening is that ColdFusion is picking up my system environment variables and is making them available via the CGI scope. Here are some of the environment variables configured on my home PC:

So I should no be able to do something like the following:
Produces :- Windows_NT
Produces :- 2 (I have a dual core CPU).
The other thing I learnt was that you can use any nonsense (so long as it's a valid ColdFusion variable name) with the CGI scope:
Interesting!
3 Comments
[Post comment]
1
Posted by David Beale | Monday 09 April 2007 2:55 PM
Just tried to re-create this and only get "Variable X is undefined" Errors.
I would be interested in finding out how you got this behavior, and to try and wrap the functionality in a cfc/tag etc.
2
Posted by James Netherton | Tuesday 10 April 2007 8:41 AM
What OS did you try that on?
If it was Windows, then that's strange because I've got this to work on my home PC and laptop, plus the work PC.
I'll give it a spin on my Mac and see what happens.
3
Posted by David Beale | Tuesday 10 April 2007 3:02 PM
It was a bog standard 2003 Install.
Simple .cfm template with;
<body>
<cfoutput>#temp#</cfoutput>
</body>