从 TCL 打开文件及其关联应用程序的最佳方法是什么? [英] What is the best way to open a file with its associated application from TCL?
问题描述
我在 Windows 上有一个 TCL/TK 应用程序.使用关联程序打开文件的最佳方法是什么?例如,我正在生成一个 PDF,我希望它自动打开.
I have a TCL/TK app on Windows. What is the best way to open a file with its associated program? For example, I am generating a PDF, and I want it to open automatically.
我一直在使用:
proc OpenDocument {filename} {
if {[catch {
exec rundll32.exe url.dll,FileProtocolHandler $filename &
}]} {
tk_messageBox -message "Error opening $filename."
}
}
但我不确定它有多健壮,我想要一个更好的错误消息.例如,我如何才能检测是否安装了任何程序并与 PDF 相关联?
But I'm not sure how robust it is, and I would like to have a better error message. For example, how can I even detect if any program is installed and associated with PDFs?
我知道许多程序(包括 Foxit PDF Reader)在HKEY_CLASSES_ROOT.extension"下添加了一个注册表项,但 Adobe Reader 似乎使用不同的系统.
I know that many programs (including Foxit PDF Reader) add a registry entry under "HKEY_CLASSES_ROOT.extension", but Adobe Reader seems to use a different system.
有什么最佳实践吗?我将向几百个用户部署我的程序,我想相当确定如果有人有奇怪的配置,不会出现普遍的问题.
Is there any one best practice? I am going to be deploying my program to a few hundred users, and I want to be fairly sure there won't be widespread issues if someone has an odd configuration.
谢谢.
推荐答案
I would write (for Tcl 8.5)
I would write (for Tcl 8.5)
exec {*}[auto_execok start] "" $filename
(讨论此处).不过这可能会显示一个 cmd 窗口.
(discussion here). That may display a cmd window though.
如果你有一个早期的 Tcl,
If you have an earlier Tcl,
eval exec [auto_execok start] {""} [list $filename]
这篇关于从 TCL 打开文件及其关联应用程序的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!