INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to find application path for a document

How to find application path for a document

(OP)
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

RE: How to find application path for a document

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

RE: How to find application path for a document

(OP)
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.

RE: How to find application path for a document

You can read file associations from Registry
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\

RE: How to find application path for a document

(OP)
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

RE: How to find application path for a document

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

RE: How to find application path for a document

Yes, it works like Bong suggested.

RE: How to find application path for a document

(OP)

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

RE: How to find application path for a document

(OP)
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.

RE: How to find application path for a document

(OP)
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:
http://www.tek-tips.com/viewthread.cfm?qid=1687220
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

RE: How to find application path for a document

I don't know if this will work but have you tried "\=" instead of "=", that is, escaping the special character?

_________________
Bob Rashkin

RE: How to find application path for a document

Hi

Quote (Bob)

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 cmd ( or something else on the Windows side ). So I would try Windows-like escaping : ^= .

Feherke.
http://feherke.github.com/

RE: How to find application path for a document

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close