HI I am trying to open docx using cfexecute. While...
# cfml-general
s
HI I am trying to open docx using cfexecute. While crosschecking with CMD, its opening fine. What am I missing here? I am only getting blank screen. Checked log also, no issues there. Am using CF2021. Anything needs to be configured in the admin settings? Please advise.
<cfexecute name="C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"
arguments="#expandPath('./test.docx')#"
timeout="10">
</cfexecute>
a
Sounds like your CF code is doing exactly what I'd expect. What do you expect it to do?
s
I just want to open the docx file
a
It'll try and open it on the server for the ColdFusion user - is that what you want?
s
Um if we run this command on the CMD, "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" "D:/cfexecute-openfile/test.docx". the test.docx automatically open using MS office or somethjing. I am trying to do that using cfexecute
The issue is the file is not opening, I am only getting blank screen, didnt get any error too. Anything else needs to b e configured/updated in the settings?
a
OK, so you said "I am only getting blank screen" - the CF page in your browser will be blank - opening a executable on the machine running ColdFusion will not cause the Word doc to open in the browser.
Secondly when that cfexecute runs, it runs as the user that the ColdFusion service is using - so won't show to another user on the same machine.
Is Word even installed on the server running ColdFusion?
s
Yeah its installed ofc
a
What are you expecting to see in the browser when you run that cfexecte?
s
I dont want to see anything in the screen, I expected the file to be opened, but it didnt. In the screen I didnt get any errors.
a
So you are running ColdFusion on the same PC that has Word on it and you are using a browser on the same PC and ColdFusion is running as the same user account as is currently logged on to that PC?
s
YES
a
That's a very strange scenario!
s
Yeah, I am not sure why!
a
OK, so I think you want this (but I'm guessing!)....
Copy code
<cfexecute 
  name="CMD"  
  arguments="C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" "D:/cfexecute-openfile/test.docx"
           timeout="10">
</cfexecute>
There are some additional attributes you can add to capture some info https://cfdocs.org/cfexecute
s
Already tried with name attribute too., let me check if other attributes can help
a
Note that my
name
value is "CMD" - as you want to run in the context of the command prompt
s
Yeah tried with CMD only!
I've tried errorvariable and errorfile attributes to check whether the error occurs in stream, but there are no errors.
a
Hmm - I don't know. I still don't understand your use case. If you are already logged into the PC why do you need CF to open a Word doc for you?
s
I am implementing a functionality like file explorer in the application, need to open any file exists there. Thats my usecase here,
e
You should have executed a PowerShell or batch command to do whatever you want with your Word file. It comes back down to what you are really trying to do with the Word file. I say that because WINWORD.exe is not designed to run in the command prompt.
☝🏻 1
☝️ 1
CFdirectroy is what you would want to use.
s
No but cfdirectory can't open the external app right?
a
> I am implementing a functionality like file explorer in the application, need to open any file exists there. Thats my usecase here, Again - you already have windows explorer why do you need CF it is pointless as will only ever work if ColdFusion is installed on the same PC as Word is installed on and running as the same user as is currently using the browser on the same PC. It will not work over the internet.
All you can do is to get CF to download that file via the browser. The user can then open the download in Word on their local PC.
Something like this:
Copy code
<cfcontent
	deletefile="false"
	type="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
	file="#expandPath('./test.docx')#">
e
you could loop through all the contents of a directory
the code is cfdirectory action ="LIST"
s
Thanks @Evil Ware I've already did all those for showing folders and the files. I tried to open the docx using cfexecute as we normally do in our windows. Unfortunately I didnt get any exact solutions. Thank you @aliaspooryorik for your inputs.
e
@Sathya M What are you exactly trying to do with the docx file? You are asking the server to open it, which java doesn't understand the os graphics components of winword. Are you trying to convert the file to another format?
Since I have to get busy, if you are trying to open and do something with the file on the Coldfusion server, natively with Coldfusion you will want to open the file, parse it as an XML document, and then remove a lot of MS-only formatting. CFDOCUMENT would do this with older word files, and may do it with docx files, but it requires open office installed on the server. Apache POI will let you do it with java, and python has multiple libraries such as apose to convert it.
👍 1
g
just use cfcontent to read the doc file and display it on browser, why using the cfexecute to do this
even with the fileexplorer functionality you are bui8lding, what if the user does not have the word installed then what is the fallback to this
m
Like multiple people have tried to figure out.... You are saying you are trying to recreate an explorer feel. Is this for a client connecting to a secondary web server? Are you connecting from PC with a web browser to another computer a web server running ColdFusion? Then what is happening is your spinning up winword on the server and it is sitting there you could probably open up a task manager and find multiple instances of winword running . CFEXECUTE primary use case is a task runner for non- GUI type tasks. Things that complete the job they are asked to without kicking off multiple processes or that are waiting for user input. Now any use of CFEXECUTE on a production server does need to be investigated because it does open you up to a huge potential avenue of someone taking advantage and compromising your system with a hack. If you are running on the local machine then CFEXECUTE might work as long as you are running in the same context as the user who is running it, but utilizing ColdFusion as a shell on top of windows or anything else is more overhead then its worth there is much much better alternatives.
👍 1
💯 1
a
I agree with @aliaspooryorik / @Michael Schmidt. @Sathya M, back up a bit. Forget about the solution. Clearly articulate the problem you are trying to solve. The description should not reference any code or programming techniques at all. Just explain what problem you are trying to solve. Start with "My users want to..."
👍 1
s
I am implementing a page in the look and feel of file explorer, user can create new folders, upload files from their system to the created folders. BUt it is not going to connect with other PCs or anything. So the user can upload any pdf,docx to their folders. While clicking that documents, I just wanted to use cfexecute to trigger the external application to open the documents they've uploaded.
a
upload files from their system
This is crux of the problem... You had a user "Albert" who is sat at a PC in Australia. Albert is logged into your ColdFusion Application. The ColdFusion Application is running on a server in Bali. The cfexecute command runs on the server in Bali. Albert in Australia is never going to have a Word document open on their PC as they are completely different systems running on different machines in different countries.
Sure Albert can upload a file over the internet to the server in Bali. Equally Albert can download a file over the internet from the server in Bali. Albert can NOT have a server in Bali open a Word Doc on their PC in Australia.
👍 1
m
So the user can download the file and open it if they have a way to open it, what happens to a downloaded file has so many ramifications and is completely driven by however a users personal computer and web browsers are configured. If you are utilizing OneDrive/SharePoint you could potentially have them open the document in the web browser utilizing some of Microsoft's built in tools, but it does complicate things, and poses the question why cloud storage isn't being utilized for this effort anyways. Honestly this idea about downloading files apply to any content on the web it just so happens that most web browsers understand CSS, HTML, JavaScript, Images, and PDFs... they however don't understand natively docx and what to do with them, which is a good thing because of the additional ramifications someone could potentially cause by having a rogue docx. Now if you are on a controlled intranet you have a little more control of how one opens documents, or how their systems might be configured.
👍 1
s
Thank you all for your suggestions and help. It makes more sense. Thank you!