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

Into the Box 2024 - Conference Slides are out!

Into the Box 2024 - Conference Slides are out!

Did you miss the live event? Get a glimpse of the fantastic content our speakers covered by reviewing their slides. Dive into topics like AWS, Cloud, Hosting, Migration, Security, CFML, Java, CommandBox, ContentBox, and more. Don't miss these valuable resources, and join us for upcoming events!

Maria Jose Herrera
Maria Jose Herrera
July 03, 2024
Ortus June 2024 Newsletter!

Ortus June 2024 Newsletter!

Welcome to the latest edition of the Ortus Newsletter! This month, we're excited to bring you highlights from our sessions at CFCamp and Open South Code, as well as a sneak peek into our upcoming events. Discover the latest developments in BoxLang, our dynamic new JVM language, and catch up on all the insightful presentations by our expert team. Let's dive in!

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang June 2024 Newsletter!

BoxLang June 2024 Newsletter!

We're thrilled to bring you the latest updates and exciting developments from the world of BoxLang. This month, we're diving into the newest beta release, introducing a new podcast series, showcasing innovative integrations, and sharing insights from recent events. Whether you're a seasoned developer or just getting started, there's something here for everyone to explore and enjoy.

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024