0

I am running the following command using ColdFusion's cfexecute: composite -geometry +2+2 "C:\Inetpub\wwwroot\isubscribe_uk\diomedes\www\images\newsletter\316\resized.png" "C:\Inetpub\wwwroot\isubscribe_uk\diomedes\www\images\newsletter\templateImages\isubscribe\blank.png" "C:\Inetpub\wwwroot\isubscribe_uk\diomedes\www\images\newsletter\316\part1.png"

<cffunction name="executeWrap" returntype="string">
    <cfargument name="commandToRun" type="string" required="Yes">
    <cfargument name="cmdArg" type="string" required="Yes">

    <cfset var result = "">
    <cfexecute name="#arguments.commandToRun#" arguments="#arguments.cmdArg#"
                                variable="result" timeout="15" />
    <!--- <cfdump var="#arguments#">
    <cfdump var="#result#"> --->
    <cfreturn result>


 </cffunction>

For some reason the above thing does not work. Though when I run the command directly onto the command prompt then it works.

Any ideas please?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
nasaa
  • 2,701
  • 8
  • 47
  • 76
  • Are you getting an error (check the logs)? Does the ColdFusion user have rights to execute the exe file? How are you escaping the quotes? If you dump out the `arguments.cmdArg` variable before the `cfexecute` call what do you get? – Miguel-F Jul 03 '13 at 17:35
  • 1
    1) "Does not work" is ambiguous. What is the actual result? Are you getting any output at all: variables, error logs, etcetera ? 2) It is always a good idea to specify the **full path** to the executable ie `c:\path\to\composite.exe` to ensure runtime.exec can locate the file. 3) As @Miguel-F mentioned, what user account is the ColdFusion server running under? Is it the same account you used to test via the command line? – Leigh Jul 03 '13 at 17:43
  • I had problems with cfexecute and appcmd.exe. I ended up using the command shell (cmd.exe) to get it to work. You can see my response in this question/answer for more info: http://stackoverflow.com/questions/8438342/cfexecute-not-executing-appcmd-exe/8485021#8485021 – Scott Jibben Jul 09 '13 at 20:33
  • That is a good suggestion too. Just be sure to use the full path like in @ScottJibben's example. – Leigh Jul 11 '13 at 20:25

1 Answers1

0

CFExecute ignores anything sent to standard error by the called process. To be able to see if there is any error output generated, add the "errorVariable" argument to your cfexecute call, then check if there is anything there and let your script react accordingly.

<cfexecute name="..command to run..."
                arguments='.. your arguments...'
                variable="results"
                errorVariable="errorOuptut"
                ></cfexecute> 

<cfif len(errorOuptut)>
    <cfthrow message="#errorOuptut#" />
</cfif>

More info here: http://www.raymondcamden.com/index.cfm/2008/4/9/ColdFusion-801-change-to-CFEXECUTE

oarevalo
  • 3,298
  • 1
  • 22
  • 19
  • *CFExecute ignores anything sent to standard error* Not exactly. Prior to 8.0.1, cfexecute did not capture stderr which could cause the process to hang. Version 8.0.1, added the ability to capture stderr and send it to the new `errorVariable` attribute. – Leigh Feb 17 '14 at 21:17