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

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024
Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024