question about cfexecute: I have a command that wo...
# cfml-general
m
question about cfexecute: I have a command that works great when I run it on the command line, but when I try to run it via cfexecute, it does nothing. The command takes as arguments a source file and a destination file:
magick "c:/code/temp/sourcePic.png" "c:/code/temp/destPic.jpg"
and my cf code for it is:
Copy code
cfexecute(
	name="#pathToIM#",
	timeout="60",
	arguments='"/temp/sourcePic.png" "/temp/destPic.jpg"',
	variable="result",
	errorVariable="error"
)

writedump({
	result: result,
	error: error
});
d
File system permissions maybe? Agree that it should complain if it can't do the thing. That may be one of the reasons a previous employer moved off of magick. Don't remember why, but they did.
m
ah, good idea - I'll look at the permissions issue
m
As far as paths to the images, I'm pretty sure it needs to be the full path, my calls look like this
cfexecute( name='convert', arguments='"#fileIn#" #arrayToList(argsIn, " ")# "#fileOut#"', variable="Results", errorVariable="Error", timeout="60");
I think whenever I install on local windows, I install something from their optional list like 'extra convert utilities'', our servers are all linux (not sure how they were installed), this call works for both. I do catch errors when it fails. my fileIn/fileOut are always full path.
m
I'm running CF in a docker container, and have the target directory mapped as persistent volumes in my compose file as
- c:/code/temp:/app/temp
. My
pathToIM
is
"/temp/ImageMagick/magick.exe"
and it runs w/o erroring, but if I were to try giving it
"/app/temp/ImageMagick/magick.exe"
then it says "no such file or directory", so I'm thinking the
/temp
based paths are correct for the input/output images. I'm not very docker savvy though, so 🤷‍♂️
the odd thing is that if I give it a bad path for
name
, it errors. If I run the same command on the command line directly and provide a bad path for the source image, it errors. But if I provide a good
name
and a bad source image path with cfexecute, it just runs w/o erroring, returns empty string for variable and errorVariable, and w/o producing any output file
aha! figured it out. It really was a docker thing. I created a test.bat file that just has
type nul > test.txt
in it and put it in a docker-mapped directory. Running that via the command line creates the test.txt file in the same folder as the .bat file. However!... running the exact same .bat file via cfexecute produces the test.txt file in the web root directory! (probably because that's the context that cfexecute runs the command from.
It's so weird that it has to have the file system path to the .bat file (really, I guess that whatever the
name
attribute is must be in terms of the docker file system), but that when it executes that command that any files it is working with must be thought of in terms of the context that CF itself is running in, which is the web root.
so. blisteringly. confusing. and. frustrating.
but whatever
thanks everyone for your help 🙂
a
It's not really that confusing though. If you did this in a normal shell, what would you expect of:
Copy code
cd c:\temp
c:\bin\createFileInWorkdingDir.exe makeme.txt
You'd expect
makeme.txt
to be created in
c:\temp
, right? The location of the executable (which is what you're giving
<cfexecute>
) bears no relation on the directory it will use to work in. The issue is that CF doesn't allow you to tell it which directory to work in (Lucee does, btw). CF's docs should be updated to say this though. Ping @saghosh
‼️ 1
BTW I suspect you are mistaken here:
Running that via the command line creates the test.txt file in the same folder as the .bat file.
I would expect the file to be created in your current directory, not the directory the batch file is in.
Copy code
C:\temp>copy con c:\bin\createFile.bat
type nul > test.txt
^Z
        1 file(s) copied.

C:\temp>type c:\bin\createFile.bat
type nul > test.txt

C:\temp>dir
 Volume in drive C is OS
 Volume Serial Number is 7AB5-679F

 Directory of C:\temp

08/06/2022  19:25    <DIR>          .
               0 File(s)              0 bytes
               1 Dir(s)  835,448,934,400 bytes free

C:\temp>c:\bin\createFile.bat

C:\temp>type nul  1>test.txt

C:\temp>dir
 Volume in drive C is OS
 Volume Serial Number is 7AB5-679F

 Directory of C:\temp

08/06/2022  19:26    <DIR>          .
08/06/2022  19:26                 0 test.txt
               1 File(s)              0 bytes
               1 Dir(s)  835,448,999,936 bytes free

C:\temp>