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 23 Launched

BoxLang 1.0.0 Beta 23 Launched

The latest release of BoxLang, Beta 23, marks a significant step forward in our journey to create the ultimate dynamic language for the JVM. Packed with powerful new features, important bug fixes, and thoughtful optimizations, this update is designed to make your development experience smoother, faster, and more reliable, especially after now starting to take 100s of comments and bug reports from our community.

Luis Majano
Luis Majano
November 23, 2024
TestBox Latest Updates and News!

TestBox Latest Updates and News!

We’re thrilled to have launched the new TestBox website and TestBox 6.0! If you haven’t had a chance to explore yet, visit TestBox to discover updated documentation, powerful resources, and features that make testing more efficient than ever.

Maria Jose Herrera
Maria Jose Herrera
November 21, 2024
Is Your ColdFusion Application Ready for the Future?

Is Your ColdFusion Application Ready for the Future?

In a rapidly evolving digital world, maintaining performance, security, and scalability for ColdFusion applications is more challenging than ever. Whether you're using Lucee or Adobe ColdFusion, legacy systems can become a bottleneck for growth, innovation, and user satisfaction. The need to future-proof your ColdFusion applications has never been more critical.

But where do you start?


The Hidden Costs of an Outdated ColdFusion Application

As you...

Cristobal Escobar
Cristobal Escobar
November 21, 2024