运行 来自其他目录的 tcl 脚本,而脚本引用本地文件
Running tcl Script from other directory while script refer to a local file
有两个或更多脚本。
脚本 A
#Script A
setenv K1 V1
脚本 B
#Script B
source "script A"
# some code
当我 运行 从它的位置编写脚本 B 时,它工作正常。
但我需要从其他位置 运行 它,例如:
_> /some/other/location/ # tclsh pathtoscriptB/script.tcl
它给出错误
无法读取文件 "script A": 没有那个文件或目录。
注意:脚本的位置可以根据使用它的用户而改变。
尝试页面末尾给出的技术 http://wiki.tcl.tk/1384 -
适应这种情况,脚本 B 会做:
source [file join [file dirname [info script]] "script A"]
有两个或更多脚本。
脚本 A
#Script A
setenv K1 V1
脚本 B
#Script B
source "script A"
# some code
当我 运行 从它的位置编写脚本 B 时,它工作正常。
但我需要从其他位置 运行 它,例如:
_> /some/other/location/ # tclsh pathtoscriptB/script.tcl
它给出错误
无法读取文件 "script A": 没有那个文件或目录。
注意:脚本的位置可以根据使用它的用户而改变。
尝试页面末尾给出的技术 http://wiki.tcl.tk/1384 - 适应这种情况,脚本 B 会做:
source [file join [file dirname [info script]] "script A"]