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

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023