What is the best way to open a file with its associated application from TCL?

前端 未结 3 1100
太阳男子
太阳男子 2021-01-25 07:49

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.

相关标签:
3条回答
  • 2021-01-25 08:30

    There's an example to see what the association is on the registry man page

    package require registry
    set ext .tcl
    
    # Read the type name
    set type [registry get HKEY_CLASSES_ROOT\\$ext {}]
    # Work out where to look for the command
    set path HKEY_CLASSES_ROOT\\$type\\Shell\\Open\\command
    # Read the command!
    set command [registry get $path {}]
    
    puts "$ext opens with $command"
    
    0 讨论(0)
  • 2021-01-25 08:50

    I would write (for Tcl 8.5)

    exec {*}[auto_execok start] "" $filename
    

    (discussion here). That may display a cmd window though.

    If you have an earlier Tcl,

    eval exec [auto_execok start] {""} [list $filename]
    
    0 讨论(0)
  • 2021-01-25 08:51

    For the records: Using the Tcl extension TWAPI, one might also want to look at:

    twapi::shell_execute -path $filename

    0 讨论(0)
提交回复
热议问题