且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在其他 tcl 脚本中运行 tcl 脚本?

更新时间:2023-11-25 09:30:10

取决于你的真正意思.

一种方法是编写第三个(主")脚本

One way is to write a third ("master") script which would do

source /the/path/to/the/first.tcl
source /the/path/to/the/second.tcl

另一种方法是将上述示例中对 source 的第二个调用添加到第一个脚本的底部.

Another way is to just add the second call to source from the above example to the bottom of the first script.

对第一种方法的修正:如果要执行的脚本与主脚本位于同一目录中,则source它们的惯用方法是

Amendment to the first approach: if the scripts to be executed are located in the same directory as the master script, an idiomatic way to source them is

set where [file dirname [info script]]
source [file join $where first.tcl]
source [file join $where second.tcl]

无论当前进程的目录是什么以及项目目录位于何处,这种方式的采购都将起作用.

This way sourcing will work no matter what the current process's directory is and where the project directory is located.