Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find application path for a document

Status
Not open for further replies.

fhutt

Programmer
Jul 7, 2006
79
AU
Hello
I would like to launch an associated application using the exec procedure to open documents.
The problem is that sometimes exec doesn't find the associated application path and fails.
How do I find the path of an associated application for a document?
Thanks
Frank
 
Do I understand correctly that:
a) you're on Windows,
b) you're attempting to open a non-Tcl file from a Tcl script using [exec...],
c) you're trying to call the application rather than the file. That is, instead of [exec blah/blah/filename.doc] (for example) you're attempting [exec word blah/blah/filename.doc].

I recommend using the file name and letting the OS find the associated application.

If that's what you're doing, the problem isn't the path but probably that the file name or path has some illegal (to Tcl) syntax, like spaces.

_________________
Bob Rashkin
 
Hi Bong
Yes, you have assumed correctly.
If i enter:
exec trial.ini
with both the script and the .ini file in the same directory I get an error "couldn't execute 'trial.ini' no such file or directory'

I get the same error for different files such as blah/blah/filename.doc

Because of this error I thought that exec cannot locate associated files via the operating system.
 
You can read file associations from Registry
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
 
That registry entry will locate associations, but I still cannot get exec to find the file. For example:
[exec winword.exe trial.doc]
How does exec know how to find winword.exe?
Thanks
 
I recall that there are some peculiarities to Windows and you need to use "cmd.exe /c" to execute most OS stuff, like:
Code:
exec cmd.exe /c e:/bong/net.jpg

_________________
Bob Rashkin
 

That's a briliant idea Bong.
There are some things about this method.
1) The cmd.exe window comes up for a second (annoying).
2) The cmd window disappears but the process continues to run.
3) After the cmd window disappears, the document takes about 30 seconds to launch.
4) After the document window is closed there is an error from the exec script: "child process exited abnormally while executing 'exec cmd.ex /c filename.doc'"

If I add an '&' to the line both 3 and 4 are fixed. maybe it's the way we call cmd.exe.
I know how to stop the cmd window showing by using a .vbs script to call it.
So, the only real problem is that the cmd.exe process continues to run until the document is closed.
Thanks
 
I think I have a solution:
Create a batch file execute.bat with one line:
start "" /B %1 %2

Then create the exec line:
exec execute.bat filename.doc &
The batch file being only one line executes so fast it cannot be seen on the screen and the document launches. The command processor completes its operation and the process closes. The tcl script continues and completes with the document being closed or not.
For some reason, without the '&' the command processor launches but does nothing, so the '&' is required.
 
I still need your help.
It works as stated in my last post fine for documents. However, if I want to launch my web browser (Firefox) with a URL, it only works correctly if there are no symbols in the URL. An example of a URL that does not work is:
The batch file %1 variable contents is truncated before the '=' character. I tried using a separate batch file to call the execute.bat and the same occurs. I can fix it by placing the URL in inverted commas. This works.
However, I am having trouble placing the URL in inverted commas in TCL so it arrives at the execute.bat command line (%1) in inverted commas. I have tried:
exec execute.bat "$url" &
or
exec execute.bat \"$url\" &
They don't work.
Thanks
 
I don't know if this will work but have you tried "\=" instead of "=", that is, escaping the special character?

_________________
Bob Rashkin
 
Hi

Bob said:
I don't know if this will work but have you tried "\=" instead of "=", that is, escaping the special character?
I think the command is altered by [tt]cmd[/tt] ( or something else on the Windows side ). So I would try Windows-like escaping : ^= .

Feherke.
[link feherke.github.com/][/url]
 
The '\' is not an escape character in Dos/Windows.
I tried the '^=' and '^&', but they don't work.
I have worked out a solution by, not using escape sequencing but by substitution.
regsub -all {=} $url {equal} url
regsub -all {&} $url {and} url
exec execute.bat $url &

Then in the batch file I substitute the other way around. This does work. but rather complicated, all because I don't know how to send the URL in inverted commas to the batch file.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top