How to run tcl script inside other tcl script?

tcl
d_pilot picture d_pilot · Feb 14, 2012 · Viewed 29.3k times · Source

I have two tcl scripts. I want to run the second script when the first finished. How can I do it?

Answer

kostix picture kostix · Feb 14, 2012

Depends on what do you really mean.

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

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

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.