{"id":4,"date":"2015-09-16T12:35:27","date_gmt":"2015-09-16T12:35:27","guid":{"rendered":"http:\/\/www.blueradial.com\/blog\/?p=4"},"modified":"2015-09-16T20:15:27","modified_gmt":"2015-09-16T20:15:27","slug":"cfexecute-on-unix","status":"publish","type":"post","link":"http:\/\/www.blueradial.com\/blog\/index.php\/2015\/09\/16\/cfexecute-on-unix\/","title":{"rendered":"CFEXECUTE on Unix"},"content":{"rendered":"<p>Usually, I don&#8217;t have many issues that are unix-specific when working in ColdFusion. CFEXECUTE is one of those tags that is a little more, shall we say&#8230; annoying? It&#8217;s quite common to try and execute a command line in Unix and have no result and no errors.<\/p>\n<p>Here&#8217;s some tips that I&#8217;ve found helpful throughout the years:<\/p>\n<ol>\n<li>Try specifying the full path. Don&#8217;t just &#8220;tar&#8221; &#8220;ln&#8221; or &#8220;echo&#8221; &#8212; specify the full path, like &#8220;\/usr\/bin\/ln&#8221; instead.<\/li>\n<li>You do need to make sure that you have permissions to execute that command. Try it manually as your CF user.<\/li>\n<li>Arguments can be tricky. The <a href=\"http:\/\/help.adobe.com\/en_US\/ColdFusion\/9.0\/CFMLRef\/WSc3ff6d0ea77859461172e0811cbec22c24-7d56.html\" target=\"_blank\">CF docs<\/a> say, if passed as a string, it needs to be &#8220;tokenized into an array of arguments&#8221; and &#8220;The default token separator is a space; you can delimit arguments that have embedded spaces with double-quotation marks.&#8221; If passed as an array, &#8220;elements are copied into an array of exec() arguments&#8221;. If it&#8217;s a simple argument, using a string is fine. For something with multiple arguments, I&#8217;ve found that it&#8217;s just cleaner to use the array convention.<\/li>\n<li>Always specify a timeout value.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3>Here&#8217;s a few examples&#8230;<\/h3>\n<p><strong>Creating a symlink:<\/strong><\/p>\n<pre class=\"brush: coldfusion; title: ; notranslate\" title=\"\">&lt;cfexecute name=&quot;\/usr\/bin\/ln&quot; arguments=&quot;-s &quot;&quot;#myDir##myFilename#&quot;&quot; #symlinkDir#\/#symlinkFilename#&quot; timeout=&quot;5&quot; \/&gt;<\/pre>\n<p><strong>Creating a zipped tarball (data.tar.gz):<\/strong><\/p>\n<p>In this example, I&#8217;m creating an array of arguments for both cfexecute tags, just because it looked cleaner.<\/p>\n<pre class=\"brush: coldfusion; title: ; notranslate\" title=\"\">\r\n&lt;cfset tarArgs\u00a0 = [ &quot;-cf&quot;, &quot;#myDirectory#\/data.tar&quot;, &quot;-C&quot;, &quot;#directoryOfFilesToGet#&quot;, &quot;.&quot; ] &gt;\r\n&lt;cfset gzipArgs = [ &quot;#myDirectory#\/data.tar&quot; ] &gt;\r\n&lt;cfexecute name=&quot;\/usr\/bin\/tar&quot; arguments=&quot;#tarArgs#&quot; timeout=&quot;60&quot; \/&gt;\r\n&lt;cfexecute name=&quot;\/usr\/bin\/gzip&quot; arguments=&quot;#gzipArgs#&quot; timeout=&quot;60&quot; \/&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Usually, I don&#8217;t have many issues that are unix-specific when working in ColdFusion. CFEXECUTE is one of those tags that is a little more, shall we say&#8230; annoying? It&#8217;s quite common to try and execute a command line in Unix and have no result and no errors. Here&#8217;s some tips that I&#8217;ve found helpful throughout [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,6],"_links":{"self":[{"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/4"}],"collection":[{"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=4"}],"version-history":[{"count":2,"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/4\/revisions"}],"predecessor-version":[{"id":35,"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/4\/revisions\/35"}],"wp:attachment":[{"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=4"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=4"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.blueradial.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=4"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}