Skip to main content
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with: Ryan Anklam and Jim Walker
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with: Ryan Anklam ( @bittersweetryan ) Jim Walker

Error Variable Randomly Exists After Running CFExecute In Lucee CFML 5.3.3.62

By on
Tags:

Yesterday, I was running into a bit of confusion when running the cfexecute tag in Lucee CFML 5.3.3.62. When you define your cfexecute attributes, you have the opportunity to provide both a variable attribute and an errorVariable attribute that hold the success results and the error results, respectively. When using this tag, I had assumed that the errorVariable would only be defined if an error occurred. However, it seems that the errorVariable is randomly populated with an empty string even if no error occurs during the cfexecute execution.

Demonstrating this is quite easy. All we have to do is run the ls command a few times in a row and check to see which variables exists after it is executed:

<cfscript>

	for ( i = 1 ; i <= 20 ; i++ ) {

		testExecute();

	}

	// ------------------------------------------------------------------------------- //
	// ------------------------------------------------------------------------------- //

	public void function testExecute() {

		cfexecute(
			name = "ls",
			arguments = "-al",
			variable = "local.results",
			errorVariable = "local.error",
			timeout = 5
		);

		if ( local.keyExists( "results" ) ) {

			echo( "Success .... " );

		}

		( local.keyExists( "error" ) )
			? echo( "Error exists: true &mdash; len: #error.len()# <br />" )
			: echo( "Error exists: false <br />" )
		;

	}

</cfscript>

As you can see, all this does is run the cfexecute with both the variable and the errorVariable attribute defined. We then check to see if the errorVariable exists. And, when we run this ColdFusion code, we get the following output:

Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: false
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: false
Success .... Error exists: true -- len: 0
Success .... Error exists: true -- len: 0

As you can see, in a little over half of the cfexecute tests, the errorVariable exists and is populated with an empty string even through the overall execution was a success.

Because of this seemingly random behavior, when using the cfexecute tag, it appears that you have to both check if the errorVariable exists and, if it does, whether or not it has any content. At least in Lucee CFML 5.2.9.40 and Lucee CFML 5.3.3.62 (the two different versions that I tested this on).

Want to use code from this post? Check out the license.

Reader Comments

15,674 Comments

@Zac,

Hmmm, interesting. I am not sure that I am good enough at reading Java to understand what I'm seeing there. But, even if it were to set the value in the page-context, it still seems odd that the outcome would be random :D

Later, I'll test this in Adobe ColdFusion to see if it behaved any differently.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel