2014-01-14 76 views
0

我是Tcl/tk的新手,感到困惑的方式是「希望」找到命令。tcl:希望和希望<source>區別

我可以運行其他程序以相同的方式從希望交互運行(給定一個命令,希望將運行從PATH目錄從ENV執行可執行文件),但運行時像wish <source>,調用其他可執行文件找不到CMD錯誤,我必須使用[exec "<executable_name>"]來做到這一點,我已閱讀www.tcl.tk上的文件,只發現當像wish <source>那樣運行時,沒有自動加載.wishrc(我檢查過我的磁盤上沒有這樣的文件) 。

任何人都知道爲什麼不能直接從腳本源文件調用PATH中的可執行文件?

+0

啊,'unknown'。 –

回答

2

如果Tcl找不到命令,[它執行unknown](以原始命令作爲參數),並使用該命令的結果作爲缺少命令的結果。

如果TCL在交互模式(tcl_interactive爲1,則該命令是在0級執行,沒有當前的腳本執行),它會嘗試一些其他步驟找到的東西,可能會執行運行:

if {([info level] == 1) && ([info script] eq "") && [info exists tcl_interactive] && $tcl_interactive} { 
    if {![info exists auto_noexec]} { 
     set new [auto_execok $name] 
     if {$new ne ""} { 
      set redir "" 
      if {[namespace which -command console] eq ""} { 
       set redir ">&@stdout <@stdin" 
      } 
      uplevel 1 [list ::catch [concat exec $redir $new [lrange $args 1 end]] ::tcl::UnknownResult ::tcl::UnknownOptions] 
      dict incr ::tcl::UnknownOptions -level 
      return -options $::tcl::UnknownOptions $::tcl::UnknownResult 
     } 
    } 
    if {$name eq "!!"} { 
     set newcmd [history event] 
    } elseif {[regexp {^!(.+)$} $name -> event]} { 
     set newcmd [history event $event] 
    } elseif {[regexp {^\^([^^]*)\^([^^]*)\^?$} $name -> old new]} { 
     set newcmd [history event -1] 
     catch {regsub -all -- $old $newcmd $new newcmd} 
    } 
    if {[info exists newcmd]} { 
     tclLog $newcmd 
     history change $newcmd 0 
     uplevel 1 [list ::catch $newcmd ::tcl::UnknownResult ::tcl::UnknownOptions] 
     dict incr ::tcl::UnknownOptions -level 
     return -options $::tcl::UnknownOptions $::tcl::UnknownResult 
    } 

    set ret [catch {set candidates [info commands $name*]} msg] 
    if {$name eq "::"} { 
     set name "" 
    } 
    if {$ret != 0} { 
     dict append opts -errorinfo "\n (expanding command prefix \"$name\" in unknown)" 
     return -options $opts $msg 
    } 
    # Filter out bogus matches when $name contained 
    # a glob-special char [Bug 946952] 
    if {$name eq ""} { 
     # Handle empty $name separately due to strangeness 
     # in [string first] (See RFE 1243354) 
     set cmds $candidates 
    } else { 
     set cmds [list] 
     foreach x $candidates { 
      if {[string first $name $x] == 0} { 
       lappend cmds $x 
      } 
     } 
    } 
    if {[llength $cmds] == 1} { 
     uplevel 1 [list ::catch [lreplace $args 0 0 [lindex $cmds 0]] ::tcl::UnknownResult ::tcl::UnknownOptions] 
     dict incr ::tcl::UnknownOptions -level 
     return -options $::tcl::UnknownOptions $::tcl::UnknownResult 
    } 
    if {[llength $cmds]} { 
     return -code error "ambiguous command name \"$name\": [lsort $cmds]" 
    } 
} 

首先檢查是否有任何可以執行的名稱的命令。
然後它檢查是否有任何歷史替換。 最後,它會檢查此命令是否有唯一的前綴。

+1

另一件要注意的事情是,如果不需要交互式地運行,那麼依靠'未知'來處理事情被認爲是糟糕的形式。 「未知」並不是一個特別快速的機制,因爲它被認爲是一個故障恢復機制...... –

0

您可能會嘗試將路徑添加到/ usr/bin/wish腳本中。

文件在/ usr /斌/想

在/ usr/bin中/心願:POSIX shell腳本文本可執行