BlueDragon Blog
Here you'll find tips and information about making the most of BlueDragon, which offers several compelling implementation alternatives for your CFML applications. This blog was created originally by Charlie Arehart, who was New Atlanta CTO from 2003-2006.,He has since moved on to become an independent consultant but continues to answer comments raised in existing blog entries. BlueDragon continues, and you should look to the newer BlueDragon blog, from New Atlanta president, Vince Bonfanti, for more updated information.

Executing CFML from the command line (or, "where did cfml.exe go?")

posted Tuesday, 29 July 2003

Just yesterday a prospective customer asked me if we had a solution to the need to run CFML templates from the command line (in other words, without a browser).  In particular, he wanted to be able to schedule the execution of some CFML templates and he preferred to use Cron (on a Linux box) versus the CFSCHEDULE tag or built-in scheduler.

He recalled that CF5 and before had a CFML.EXE that could be used for this purpose, but he'd noticed that it was no longer in CFMX. And he wondered if we had something like it for BlueDragon?

Well, we never implemented CFML.EXE, but I do have another solution to offer. (First, I'd like to point out that there's some interesting history about what CFML.EXE really was about, the original CGI interface to CF, as discussed in the Admin manual of the CF4 docs. Second, if you're new to CFML.exe, I did a tip on it on 1/24/2001 at my former site, Systemanage.com.)

But as for how to execute CFML templates from the command line, there is a bit of a workaround. A post by Macromedia Senior Product Support Engineer Tom Link, on a mailing list, reminded me of it today.  And it's a solution that works for BlueDragon as well, of course.

The GNU WGet tool offers what to CFML developers can be described as a command-line CFHTTP. It's just a way to execute any server-side URL from a command line and save its results. And like CFHTTP, it can also return either absolute or relative links, use HTTPS, save the server headers, and more. (Indeed, it's worth repeating that the customer was seeking a command-line means to execute CFML templates, so he obviously couldn't use CFHTTP to solve the problem.) The tool also runs on both Windows and most *nix systems, supports cookies, can use filename wildcards, can recurse directories, can restart failed downloads, and more.

Just download it from the page offered above. Then you can have it execute any URL (including BlueDragon pages). I'll share some more tips later in this entry. For those who want to follow along, you'll want to first download the tool.

Downloading the tool

Linux users are generally more comfortable with downloading such tools, so I'll offer some tips for Windows users. Note that the page offers a different link for getting the Windows versions. And for those not used to downloading tools from sites like GNU, you'll note the use of the term "binaries". That just means a compiled executable version of the tool, versus a source code version for you to compile yourself.

Indeed, on the page offered for downloading the tool, you will be offered filenames with a "b" (for binary) and "s" (for "source"). Select a "b" version, such as wget-1.8.1b.zip. (Indeed, if you read the docs, you learn that version 1.8.2 and above support SSL but require another ssllib library to make them work. If you don't need SSL, just choose 1.8.1 to get started.)

Then simply download the zip, and extract the 3 programs (wget.exe, wget.hlp, and wget.html) into any directory on your system. They DO NOT need to go into your webroot or anything special. Indeed, pay attention that the zip has them stored within a folder so if you don't want that, deselect "use folder names" or the equivalent in whatever zip extraction tool you use.

Using the Tool

This is a rich tool with a lot of features. It will pay to read at least the first few pages of the manual. Note that the HTML file in the download is the help file in HTML format. It's in effect a 50-page user guide and worth printing out. About halfway through the document, there's an "Examples" section. Check that out. If you prefer to read about it without downloading it, the manual's available online and the direct link to the examples section is http://space.tin.it/computer/hherold/wget.html#Examples. There's also a site that includes a "mini how to" and some sample batch files for using key features. See http://space.tin.it/computer/hherold/.

With the tool in place, you'll find that it can indeed call upon any URL at all. Just be aware of a few things.

First, whereas CFML.exe expected the absolute drive path to a file (such as c:\inetpub\wwwroot\test.cfm), this tool obviously expects URLs so you need to change any Cron jobs or AT scheduled tags (for more on that, see http://www.systemanage.com/cff/cftips5.cfm#otherscheduler)

What's the result of running a template with Wget? Again, whereas the cfml.exe simply returned output to its caller (and you had to tell your scheduler task to save the output), the wget tool has much more flexibility. The default behavior is to create a file holding the HTML of the desired page, using the same name as that in the URL, in the current directory (where wget.exe is installed). So if you browse a page called test.cfm, you'll end up with a file called test.cfm, holding of course the HTML, not the CFML. Just be aware of that.

There are various command line options that may help if you prefer it to work differently. Look at the options -O (aka --output-document=file) to direct the output to a file and -E (aka --html-extension) to just append ".html" to whatever filename it would return.

Indeed, if you want it to work as cfml.exe did and just return the output not to a file but to the command-line or scheduler executing the wget command, there's a trick for that. Use "-O -" before the URL. That says "create the output, but send it to the standard output".

One last point: note that the tool also reports the time it took to download the page and the byte count for what's retrieved, which can make it interesting to use as a rudimentary tool for testing performance, white space handling, and more.

Hope this has been helpful. And do look at the many options the tool has (such as for cookie processing, changing absolute links to relative ones, saving headers, using wildcards, recursing directories, and more.)




1. a reader left...
Tuesday, 29 July 2003 11:17 am

Great piece of advice that; wget is one of those utilities that you never know how you ever managed with out it. I use it all the time for downloading RPMs and installation files on Redhat, and also on Windows inside of cygwin. Highly recommended.

Alan


2. a reader left...
Tuesday, 29 July 2003 11:51 am

Those of you looking to use wget without having to install cygwin can look here : http://www.weihenstephan.de/~syring/win32/UnxUtils.html

Todd


3. Charlie Arehart left...
Tuesday, 29 July 2003 12:29 pm

Todd, that's an interesting URL, for sure. But just out of curiosity, if you're suggesting that one would otherwise "have to install cygwin" to use wget on Windows, that isn't the case. I pointed out in the note that there were already Windows binaries available from the Wget project page. Or did I misunderstand you?


4. a reader left...
Thursday, 11 September 2003 10:29 am

"In particular, he wanted to be able to schedule the execution of some CFML templates and he preferred to use Cron (on a Linux box) versus the CFSCHEDULE tag or built-in scheduler."

Can you give us some insight as to *why* he preferred that unorthodox approach?

Joe Grossberg [josephgrossberg@hotmail.com]


5. a reader left...
Thursday, 11 September 2003 4:07 pm

This is a great article. COLDFUSION NEEDS COMMAND-LINE interface! If this takes off, it will be a big hit. One thing really lacks with coldfusion is that we don't have the command line ability. This means that we need to look at things like perl/shell scripts/python, etc. We NEED the coldfusion interpreter!

Joe Saberi


6. a reader left...
Thursday, 11 September 2003 11:19 pm

Joe, when you ask why "he preferred that unorthodox approach", do you mean why he wanted to schedule the processing of a page, or why he wanted to use Cron versus the CFSHEDULE tag or admin scheduler?

I'll assume you mean the former. Are you thinking he should just use the CFCACHE tag? The thing is, it has some limitations and sometimes just doesn't do the trick. Also, some prefer the manual approach just because it's more familiar to them.

But the real point, however, was simply that sometimes people want command-line access to execute CFML pages, for whatever reason.

charlie arehart [charlie@newatlanta.com]


7. a reader left...
Wednesday, 24 September 2003 5:00 am

I presumed that Joe meant 'why from the command line' rather than CFSCHEDULE, as there are plenty of obvious reasons for scheduling CF templates (say an email checking template, or a server downtime checker - cfcache isn't going to cut it there ;-).

Taking it from this perspective, CFSCHEDULE is (in my experience) notoriously unreliable, and it is chiefly for this reason that you may want schedule important tasks using an alternative method. There is also the point that you might want to integrate all your scheduled tasks in one place.

Ivan


8. a reader left...
Wednesday, 24 September 2003 11:50 am

Fair enough, Ivan. Only Joe can tell us for sure what he meant by referring to an alternative to CFSCHEDULE as "unorthodox". It's funny: I allowed for his meaning what you think in my reply to him, but I explained the other possibility only because I thought it may be less well-understood. But certainly, as you say, there an be a number of reasons to consider using something other than CFSCHEDULE.

I'll say, though, that you're indicting the CFSCHEDULE from experience with CF, right? Not BlueDragon? I've not head of anyone having a problem with our scheduling of tasks (whether by CFSCHEDULE or the Admin).

Not saying there would never be any, but let's at least cast any aspersions on CFSCHEDULE toward the server where you really experienced them. :-)

charlie arehart [charlie@newatlanta.com]


9. a reader left...
Friday, 18 March 2005 8:58 am

You can also just use the windows scheduler to open any url on the server, some have said this seems to run better than the scheduler

Geoffrey Barth [barth@jlab.org]


10. Charlie Arehart left...
Saturday, 19 March 2005 9:47 am

Good point, Jeffrey. I'd written on this in a couple tips back in 2001, in case anyone wants a little more info:

http://www.systemanage.com/cff/cfti ps5.cfm#otherscheduler

http://www.systemanage.com/cff/cftips5.cfm#cmdcf


11. a reader left...
Wednesday, 6 April 2005 5:19 am

I was searching high and low for a way to execute CFML asynchronously when I chance upon this blog, nice tip!

I need to generate a really huge Excel file, so using the regular get methods will almost always end in timeouts. CFMX7 have the new async gateway, but the customer does not wish to spend the money :P

Xacome


12. Alex left...
Monday, 6 February 2006 2:50 pm

Can you provide sample of using wget to run cfm page?


13. Charlie Arehart left...
Monday, 6 February 2006 3:09 pm

Alex, there's nothing about wget that is at all specific to CFM pages. See the examples offered, such as at http://xoomer.virgilio.it/hherold/wget.html, which show how to use the tool. Where they show using it to call a given URL, change it to have the URL for running the CFML page you want to run.

As I explain in the "using the tool" section, though, the tool only takes a URL (not an absolute file name as cfml.exe took), so you have to change any references to cfml.exe (scheduled tasks, chron jobs, batch files) accordingly.

There are other details of use offered above. If you still need anything explained, please be more specific.


14. Ivan left...
Wednesday, 3 May 2006 3:43 pm

Long time since I left that comment about CFSCHEDULE's unreliability and just happened back to this page through a Google search today! Of course if was indeed CF Server and not BlueDragon with the flaky CFSCHEDULE problem.

Command line interface would still arguably be useful though, if you could then just execute CF templates directly from the command line and capture the output; WGet involves setting up a website, etc. - and if the stuff you want to execute is in any way sensitive, making sure it is secured from the outside world etc...


15. Scott Stewart left...
Thursday, 15 February 2007 11:24 am

will this also work with urls that have variables? ie: http://www.foo.bar/test.cfm?I=1&j=2


16. Randy left...
Friday, 23 February 2007 3:09 pm

Does anyone know if cfml.exe was a standalone program? IE it would run without cf5 server installed?

Thanks!

Randy


17. Charlie Arehart left...
Friday, 23 February 2007 8:41 pm

That's a very interesting question, Randy. I'd never considered it. The answer is that not only must you have CF installed, but you must have it running. I just ran a test where I had a page that I called using CFML.exe, and it worked. Then I stopped the service, and ran it again, and it failed. Actually, it never responded. I had to kill the dos command (using ctrl-c), or I could have closed the dos command window.

Anyway, for anyone intrigued about this relic of the pre-CFMX era, I did a tip on how to use it back in 2001. It's not as easy as it may seem, and the error info it offers when you try to run it isn't accurate either. Check out the tip at my old site:

http://www.systemanage.com/cff/cftips5.cfm#cmdcf