CFExecute Output Not Going in Your Variable?

I’m blogging this because it’s a little tidbit I always waste about 30 minutes figuring out before I remember it.

The <cfexecute> tag can return the output of the execution into a variable if you supply one with the variable=”" attribute. However, I will try to do this, and (a) the script returns too quickly, and (b) there is no output when there should be.

There is an easy solution! <cfexecute> is expecting the timeout=”" attribute. Supply it a timeout value in seconds, and it will then wait for the script to finish executing and thus have output to store in your variable.

You may be wondering why this is necessary, because even without the timeout=”" attribute, the execution still occurs. <cfexecute> just doesn’t return any output. That’s because <cfexecute> is indeed running, it is just immediately timing out–effectively giving up on the executed process–and thus not returning the output. By supplying a timeout, ColdFusion hangs around waiting for the process to complete before returning its output.

3 Responses to “CFExecute Output Not Going in Your Variable?”

  1. Ben Nadel Says:

    Awesome tip! I definitely know people who have had to get CFX tags to handle CFExecute specifically because the output wasn’t being captured. I wonder if this would have been the better solution!

  2. Raymond Camden Says:

    Don’t forget CF801 added errorVariable as a way to get the error output into a variable as well.

  3. Jeremy Prevost Says:

    This was driving me nuts, but the timeout value totally makes sense and fixed the problem…

    Thanks!

Leave a Reply

  Theme Brought to you by Directory Journal and Elegant Directory.