The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

Thoughts on calling ColdFusion from the command line

posted under category: ColdFusion on September 18, 2006 by Nathan

One of my favorite bloggers, Sean Corfield, wrote that he wanted to see a way to invoke ColdFusion from the command line. A day or so later, Ashwin Mathew wrote how to do just that using cURL. It basically just hits your CFC path using the url invoking syntax (?method=myFunction&arg1=abc).

This doesn't really satisfy me.

It forces you to expose CFCs in your webroot, forces you to have them access=remote, and has the potential to force network access, especially if your site is using host headers or if you are accessing it via a public domain name.

It seems to me, a cleaner way to do this would be to invoke your cfc via an event gateway, and, because there is no command-line event gateway type (yet), I'm thinking a socket gateway may just be the way to go. Think about it, it's local, won't require network or dns access, connects directly and can send/receive feedback inline. Of course, telneting to it is cumbersome, so a simple jar or script that you could call seems logical. Depending on the implementation, you could even allow it access to any cfc or cfm on the system. Calling syntax would be something like:

java -jar CFCLISocket.jar com.mysite.myapp.myobject.mymethod(abc)

Simplify that through a shell script or batch file to make your life easier.

The Java behind it would make a socket connection to on a specified port and send the code you want to evaluate as a string to the event listener.

A slightly cleaner way to do this would have to be through a custom gateway specifically written for command-line invoking. It would execute the same, but the jar to invoke would be even easier to write (and potentially safer).

The best imaginable way would still have to be real actual support written into the CF server. I imagine this would be like php, where you can execute a php page straight from the CLI. Nice feature, steal it!

Of course, all of this is theoretical. Big help, I know, for those of you out there looking for an immediate solution.

Nathan is a software developer at The Boeing Company in Charleston, SC. He is essentially a big programming nerd. Really, you could say that makes him a nerd among nerds. Aside from making software for the web, he plays with tech toys and likes to think about programming's big picture while speaking at conferences and generally impressing people with massive nerdiness and straight-faced sarcastic humor. Nathan got his programming start writing batch files in DOS. It should go without saying, but these thought and opinions have nothing to do with Boeing in any way.
This blog is also available as an RSS 2.0 feed. Click your heels together and click here to contact Nathan.