2
<cfset LOCAL.cmd = expandPath('..\library\gm.exe') />
<cfset LOCAL.args = "convert image1.jpg image2.jpg" />

<cfexecute variable="gm" errorVariable="error"
 name="#LOCAL.cmd#" 
 timeout="10" 
 arguments="#local.args#" />

<cfdump var="#gm#" />

This code always results in an empty string in gm. No matter how I execute gm with or without parameters. Other examples work fine like running cmd.exe or netstat.exe as is in the CFDocs example. I get no errors thrown or warnings in errorVariable, it simply does nothing.

I modified the code, this version does not work either:

<cfset LOCAL.cmd = expandPath('..\library\gm.exe') />
<cfset LOCAL.args = "convert ""#variables.uploadDirectory##LOCAL.file.source#"" ""#variables.uploadDirectory#optimal-#LOCAL.file.source#""" />
<cfexecute  errorVariable="error"
    name="c:\windows\system32\cmd.exe" 
    timeout="10"
    outputFile="#expandPath('.\gm.log')#" 
    arguments="/C #local.cmd# #LOCAL.args#" />
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Drew
  • 4,683
  • 4
  • 35
  • 50

3 Answers3

4

Permissions problems are the most common cause. However, if you are running CF8, you might also try redirecting the error stream and adding an explicit terminate flag. Just to see if you get any output or see different behavior. Early versions did not capture the error stream, which caused some processes to hang. It was fixed in one of the CF8 updaters.

Update: I just noticed your image paths are relative. Perhaps the program is having difficulty locating them. Try using absolute paths for the images.

Update: I tested it with CF9. It does work when using absolute image paths. Though the "gm" variable is understandably empty, since the output is directed to an image file.

<cfexecute variable="gm" 
    errorVariable="errorOut"
    name="C:\GraphicsMagick-1.3.12-Q16\gm.exe" 
    timeout="10" 
    arguments="convert c:\art.gif c:\artCopyFromCF9.gif" />

<cfdump var="#variables#">  
Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103
  • I am running CF9, so I have the update that includes errorFile. I tried running this and did not receive any additional information in the stdout. – Drew May 05 '10 at 16:14
  • @Drew - A couple things a) As Ben asked, what are you expecting to happen? b) Does it actually work when executed from the command line and c) just for grins, have you tried using cmd.exe as the program and specifying gm.exe in the arguments? – Leigh May 05 '10 at 16:18
  • I posted comments above, I have updated the code to use cmd.exe directory and pass my program via /C. Also, I changed this to echo before the full path, copied this into a command prompt and it ran perfectly. – Drew May 05 '10 at 16:24
  • Maybe you did this already, but .. 1) Before you start messing with variables, did you try a very simple example with hard coded paths with no spaces to avoid quoting (like c:\temp) 2) I know you are running CF9, but did you say you _did_ try using both flags /C and 2>&1 ? 3) Which gm.exe program is this? – Leigh May 05 '10 at 16:33
  • I'll try that, I am using http://www.graphicsmagick.org/. It includes a gm.exe binary for doing simple image transformations. – Drew May 05 '10 at 16:47
  • 1
    @Drew - Okay. I have a feeling the image paths may be the problem. It is possible the program is looking for them in a different directory. So using an absolute path may help it be able to find them. I am surprised you are not getting an error though. – Leigh May 05 '10 at 17:02
1

Without seeing code or your server setup, I would guess you need to check permissions for the user account CF runs under.

If CF is running under the default user, you may need to create a user with access to whatever it is you are trying to do. Then change the service(s) to run under this user. Alternately, you could assign more liberal permissions to the resource you're trying to access.

Ben Doom
  • 7,865
  • 1
  • 27
  • 30
  • It's running as the local system, so it should have permissions to this file. It is all local on my file system. I will try messing with permissions on the file, shouldn't it be throwing a security error if this was the problem? – Drew May 05 '10 at 15:39
  • Correction, coldfusion is running under my user account. So permissions are definitely not an issue. – Drew May 05 '10 at 15:53
0

I have also encountered this with cfexecute and GraphicsMagick. I think the deal is that GM is operating asynchronously and returns before it completes. Running some tests with outputFile/errorFile instead of their variable equivalents, followed by cffile reading the fileInfo on the output file (which is empty per the test script but observed to have contents when opened), I see that the modified time of the output file with contents is actually after the last modified timestamp yielded by FileInfo.

I think if you output to a session variable or something of the sort that could be picked up by another template you could observe the results of the execution having populated the session variable, provided the other template executes after the variable is actually set.