Cross Platform Development Tips

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>

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

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 = server.os.name 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

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

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.