This probably won’t mean much to most folks who stop by here on a regular basis, but I put it up mostly in the hopes that it might be useful to someone out there trying to figiure out what their code is doing.
We use ColdFusion in one of our projects at work, and we’re still stuck on CF 5. I’ve been tinkering with writing a few custom tags to make use of the excellent PsTools package from SysInternals using the cfexecute tag, and I’ve discovered a few interesting things about cfexecute.
First of all, the obvious annoyance — in CF 5, cfexecute doesn’t provide a handy way to capture any output in a variable. You either give it an output file or it will display its output to the generated page, which means the only way to capture it in a variable is to wrap the cfexecute call in a cfsavecontent tag (this has been fixed in CFMX 6.1, which adds a ‘variable’ attribute to the cfexecute tag). But hey, I can live with that. It’s not clean, but it works.
The next interesting thing is that cfexecute will take the first output it receives and finish executing, regardless of whether the called command is complete. For example, the first PsTools command I wanted to integrate was Psinfo, to find out things like the system’s uptime. When you run Psinfo, it displays a few lines of copyright info and pauses while it queries the system for information. Cfexecute will grab this initial output and return, ignoring anything else the process might return. Which, among other things, means it’s not waiting for an exit code from the command. In this case I was able to get around it because the initial output from Psinfo is apparently on StdErr rather than StdOut. So I made a batch file that calls Psinfo and pipes StdErr to a temp file (does Windows have anything like /dev/null?), and then deletes the temp file. Cfexecute then calls the batch file (actually it calls ‘c:\windows\system32\cmd.exe /c psinfo.bat’) and receives the correct output, which I then chop up and stuff into a struct for later use.
However, I encountered this two days ago, and I tried to reproduce the problem set just now to make sure I wasn’t crazy. Unfortunately I may have strongly suggested the opposite because I can’t reproduce it, so YMMV. This is maddening…
Anyway, the next one I am sure of, which is that when cfexecute is capturing and returning the output (rather than piping it to a file using the ‘outputFile’ attribute) there is a 4Kb (which is to say, 4096 character) limit on how much it can hold. The effect when running a command that returns more than that (like, say, pslist) is that cfexecute will fill up its buffer, wait until its timeout has expired, and throw a timeout error (which you can, of course, cfcatch), leaving the actual command running indefinitely, waiting to give the rest of its output to someone who isn’t listening anymore. This too has been fixed in CFMX, but for CF 5 it seems the only answer is to use cfexecute w/ outputFile, followed by a cffile read and a cffile delete. Talk about ugly…
6 Comments
#1. Dad 05.08.2005
As you very well know, I have no idea what you are talking about, but I know you’ll get it figured out, even if it means rewriting the entire code in your spare time. You’re as bull headed as your old man! 😉
#2. Lee 03.15.2006
Hello, Just wanted to say that this information was useful to me. I am currently debugging the use of using a batch file to run some server side processing. But thanks….
#3. joel 03.15.2006
No worries; glad it was useful.
#4. Raul 08.25.2006
had the same problem running htmldoc with cfexecute, it was being too verbose, which would fill a CF buffer and stop working. Added the –quiet option to htmldoc and now it works like a charm. Thanks for the info!
#5. Geoffrey Barth 08.31.2006
We are having a similat problem with cfmx6.1 cfexecute won’t capture stderr it only grabs sdtout and puts in it the varible, CF5 got both. Any ideas before I reengineer the jar file
#6. joel 09.05.2006
Geoffrey,
That’s a good question. I haven’t had a chance to play around quite as much with the behavior of cfexecute in cfmx6.1, so I’m not sure. But if I find out, I’ll let you know. By which point you probably will have had to reengineer the jar file anyway… 🙁