Blog

Running CFML From the Command Line

Luis Majano February 20, 2015

Spread the word

Luis Majano

February 20, 2015

Spread the word


Share your thoughts

One of the features we really wanted to see in CommandBox is OS integration to be able to execute CFML as part of the OS like any other binary.  Me personally, I wanted also to script in CFML instead of convoluted BASH or any type of shell scripting language.  In CommandBox you have several ways of executing via the command line.  Let's investigate a few.

Running CFML Files

You can very easily create ANY cfm file and put any code in it and execute it via CommandBox.

run.cfm

<cfoutput>
I am running inside of CFML at #timeFormat( now() )# on #dateFormat( now(), "medium" )#
</cfoutput>

Now we can execute the file via CommandBox:

box run.cfm

And out comes the response:

I am running inside of CFML at 08:46 AM on Feb 20, 2015

This is a great way to be able to script ANYTHING, cfhttp calls, db calls, load tests, etc. The only problem at this moment for this approach is passing variables, you can't as of 1.0.0 version.

Shell Scripting

You can also leverage shell scripting with CommandBox if you are in a *Unix environment.  Just create a file with some content like this:

run

#!/usr/bin/env box

<cfoutput>Hello from CFML Land on #now()#</cfoutput>

Then make sure the file is executable by running the following:

chmod +x run

The key to scripting in CommandBox is the #!/usr/bin/env box. This is what tells the scripting engine interpreter to pass in the content of the file to be interpreted by CommandBox. Then all you need to do is execute the file:

./run

And you will then get the execution output:

jfetmac-17:tmp ortus$ ./run
Hello from CFML Land on {ts '2015-02-20 09:20:00'}

 

Add Your Comment

Recent Entries

BoxLang 1.0.0 Beta 27 Launched

BoxLang 1.0.0 Beta 27 Launched

We are excited to bring you Beta 27 with enhanced XML handling, new CLI app support, improved error handling, and expanded interoperability with Java and CFML runtimes. We've also added new HTTP event hooks, improved caching strategies, and a streamlined class resolution process to make your applications more performant, even in debug modes.

Luis Majano
Luis Majano
January 31, 2025
Into the Box 2025 | Plan Your Trip With Us!

Into the Box 2025 | Plan Your Trip With Us!

Are you ready to join us for Into the Box 2025 from April 30th to May 2nd in Washington, D.C.? Let’s make your trip planning as smooth as possible. Here you’ll find Airfare discounts, Hotel Deals and fun things to do to the the best out of your trip to D.C.

Maria Jose Herrera
Maria Jose Herrera
January 30, 2025