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 127.0.0.1 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.