从另一个目录采购TCL脚本
我有两个TCL脚本,其中一个叫另一个。第二个脚本“ version.tcl”位于工作目录的子目录(“综合”)中。
我目前已经以以下方式进行了设置并运行:
cd ./synthesis
source version.tcl
cd ../
我想将其凝结到一个可以源自脚本的命令中,而无需更改目录,这是:
source [file join [file join [[pwd] synthesis] version.tcl]]
或
source ./synthesis/version.tcl
不幸的是,上述命令都不可用。我知道这对于比我更熟悉的人来说应该很容易解决,因此,任何帮助都将不胜感激。
I have two tcl scripts, one of which calls the other. The second script, 'version.tcl' is in a sub-directory ('synthesis') of the working directory.
I currently have it set up and working in the following fashion:
cd ./synthesis
source version.tcl
cd ../
I would like to condense that to one command which can source the script without having to change directories, something along the lines of:
source [file join [file join [[pwd] synthesis] version.tcl]]
Or
source ./synthesis/version.tcl
Unfortunately neither one of the above commands works. I know this should be an easy fix for someone with more familiarity with tcl than me, so any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
source
命令在其他目录中读取文件,很好。它使用与Open
来处理文件名的机器几乎完全相同(这不仅仅是“将其交给OS”)。我们知道它有效;经过测试,这是许多人在许多平台上使用的东西。几乎可以肯定的是,该文件内部的代码期望将当前目录是包含脚本的目录。您修复的选项
执行您当前正在做的事情,或者是它更强大的版本:
<
设置PWD [PWD]
CD $目录
尝试 {
uplevel 1 [列表源$ scriptName]
} 最后 {
CD $ PWD
}
}
更新您调用的代码,以便它相对于脚本访问资源,而不是当前目录:
The
source
command reads files in other directories just fine; it uses almost exactly the same machinery asopen
to handle filenames (and that's little more than just "give it to the OS"). We know that it works; it's tested and it is something that very many people have used across many platforms.What's going wrong is almost certainly that the code inside that file expects to have the current directory be the one that contains the script. Your options to fix that are
Do what you're currently doing, or a slightly more robust version of it:
Update the code that you call so it accesses resources relative to the script, not to the current directory: