Pete Freitag Pete Freitag

Cross Platform Development Tips

Published on August 14, 2003
By Pete Freitag

The post I lost earlier today due to the power outage had a simple way of checking to see if your on a unix OS at runtime, and also some tips for writing cross platform coldfusion.

<cfset isUnix = Left(cgi.cf_template_path, 1) IS "/">

<cfset pathSeperator = "\">
<cfif isUnix><cfset pathSeperator = "/"></cfif>

Running UNIX: #YesNoFormat(isUnix)# <br />
Path Seperator: #pathSeperator#

The first line check to see if we are running unix by checking the first character of a path, if it begins with a /, then we are running unix. You can also do something like this isUnix = IS "UNIX" to set that variable, but I think my method may be a nudge faster because it doesn't deal with a synchronized scope (server scope), and it's checking a smaller string.

The next two lines find the path seperator using the same techinique, there are several ways of doing this as well, you can use the java System properties hashtable for instance. It should be pointed out that CFFILE and CFDIRECTORY will accept front slashes on windows, so one option is to just always use / to keep your apps cross platform, this can create messy paths sometimes however..

It is not very difficult to write cross platform applications in CFML as long as your aware of the differences on windows and unix, here are some of the common gotcha's

  • Application.cfm - Application.cfm must have the exact case I'm using here.
  • OnRequestEnd.cfm - Also must have the case I'm using here.
  • CFINCLUDE Template Case - The template path in your CFINCLUDES is case sensitive on unix, you can use my code review tool to find templates with incorrect case, as well as missing templates. It will also check the case on your Application.cfm and OnRequestEnd.cfm files in addition.
  • Links, Images case sensitive - All paths to links, images, stylesheets, must be case sensitive as well, there is a workaround for this one however. If you install mod_speling in apache it will redirect the client to the proper page. This may not work all that well for images, stylesheets, or form posts however.
  • CFEXECUTE - CFEXECUTE will still work on unix but the applications your executing may not.
  • COM - not supported on unix.

So those are the main issues in porting a windows CF app to unix, the main thing to remember is case sensitivity.

Cross Platform Development Tips was first published on August 14, 2003.


The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.

Try Fixinator

The weekly newsletter for the CFML Community