• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1218
  • Last Modified:

cfexecute and bat files

I have a unique problem in that I need to convert pdf pages to jpegs on the fly as users upload them. So far all my research points to a piece of software called pdf2img by http://verypdf.com. What makes it so useful is that you can run it from the command line. See http://www.verypdf.com/pdf2tif/pdf-to-image/help.htm for commands. I was hoping it would be an easy task using cfexecute on my CF7 server. So far not so good. I have never used cfexecute or bat files. Research so far has been pretty geeky so far and not directly related to my current task at hand.

When I run the following command from the command line I get the output I desire.
-i F:\test.pdf -o F:\output.jpg -f 1 -l 1

This outputs the first page of the PDF as a jpg. No problem. The problem occurs when I try to add this command to a .bat file and run it from the web with a script like so.

<cftry>
     <cfexecute
            name="F:\test.bat"
            timeout="100"
            outputFile="F:\output.txt">
</cfexecute>
     <cfcatch>
          <cfoutput>
          #cfcatch.message#
          </cfoutput>
     </cfcatch>
</cftry>

My .bat file has changed wildly in the last day so I won't even post an example here as I believe this is where the problem is. I have no idea how to launch the exe located at C:\Program Files\VeryPDF PDF2Image v2.1\pdf2img.exe

Any help is greatly appriciated.
0
visual28
Asked:
visual28
  • 3
  • 3
  • 3
1 Solution
 
wizeabeCommented:
Try this in a batch file:

-----------------------
@ECHO oFF

ECHO Waiting...
"C:\Program Files\VeryPDF PDF2Image v2.1\pdf2img.exe -i F:\test.pdf -o F:\output.jpg -f 1 -l 1"

------------------------
0
 
visual28Author Commented:
Not quite it yet.

I would like to add that from the CMD terminal I had to CD into the C:\Program Files\VeryPDF PDF2Image v2.1\ to run the pdf2img.exe

I am not sure if this is typical, or how things are typically done from the terminal do I have to change directories in the scripting for the .bat file or can you not run the exe with a full path like above?

Thanks for the help so far. I appreciate it greatly.
0
 
wizeabeCommented:
If you use the full path name as above with the quotes, it should run. Does this answer your question?

Also make sure to copy everything in between the two lines, including the last empty line.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
qz8dswCommented:
I think wizeabe's command would work better like this
"C:\Program Files\VeryPDF PDF2Image v2.1\pdf2img.exe" -i F:\test.pdf -o F:\output.jpg -f 1 -l 1

The quotes only need to be around the exe your trying to run (Or more the point the command with spaces in it).
The EXE itself will parse the rest of the commands itself.

IF however the directory your inputting from or outputting to has spaces then the command would be this.
"C:\Program Files\VeryPDF PDF2Image v2.1\pdf2img.exe" -i "F:\this is a test\test.pdf" -o "F:\this is a test\output.jpg" -f 1 -l 1

Terry
0
 
wizeabeCommented:
Thanks for that, I didn't have a utility like that with me to test my command.
0
 
qz8dswCommented:
For CFexecute itself you could try (I don't know coldfusion very well so I'm adapting some instructions from here http://www.forta.com/blog/index.cfm/2006/7/31/Using-CFEXECUTE-To-Execute-Command-Line-Utilities  )


<cfexecute name="F:\test.bat"
   timeout="100"
   variable="data">
</cfexecute>

<cfdump var="#data#">

It also should work if you done this
<cfexecute name="C:\Progra~1\VeryPD~1\pdf2img.exe"
  arguments="-i F:\test.pdf -o F:\output.jpg -f 1 -l 1"
  timeout="100"
  variable="data">
</cfexecute>

<cfdump var="#data#">

(Note how I put the path to the name into 8 characters, should work unless you have gone out of your way to turn off 8.3 names)

BUT I don't know how Coldfusion would like running with the arguments="-i "F:\this is a test\test.pdf" -o "F:\this is a test\output.jpg" -f 1 -l 1" because of all the quotes in the arguments.

IF it still doesn't work, edit your batch file and add the following
C:
cd "C:\program files\VeryPDF PDF2Image v2.1"
BEFORE you try to execute pdf2img.exe
One got ya I've read from the same blog is as follows
"There is no way to tell <cfexecute> where to execute your command. If you need to be in a specific folder when the command is executed, you should execute a batch file or script, and have it change to the desired folder and then execute the command."

Terry
0
 
visual28Author Commented:
Just wanted to follow up and say that the accepted answer worked perfectly. I did find one problem that may effect others trying to do the same thing.

I am running  CF Server on my user account  and by default, the server cannot interact with the system and therfore cannot run tha bat or run a command line process. CFServer has to be run as an admin or you will need to go to the properties of that service and check the box for allowing the service to interact with the desktop under the log on tab. and restart the service. I am sure this is a big security problem and I am looking for a better solution. Thanks again guys for all the responses.
0
 
qz8dswCommented:
Thanks visual28,
For my own curiosity which one of the options worked for you?

Terry
0
 
visual28Author Commented:
No Problem Terry,

They both worked fine however this one worked best as it would allow me to set the input and output values dynamically using a variable.

<cfexecute name="C:\Progra~1\VeryPD~1\pdf2img.exe"
  arguments="-i F:\test.pdf -o F:\output.jpg -f 1 -l 1"
  timeout="100"
  variable="data">
</cfexecute>

Mark
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now