How can I run source command and store its output in a file?
-- San
Depends on how the "output" is generated inside the script:
if it's just the returnvalue of the last command in it, then:
set fd [open a.txt w]; puts $fd [source a.tcl]; close $fd
if the a.tcl contains "puts" to stdout/stderr, you may replace
the "puts" command to do something else.
if the a.tcl contains calls to external programs that write
directly to stdout/stderr, you'll have to reopen those
channels first, but this effect will then remain even
after the sourcing.
source a.tcl does execute the commands in a.tcl within the same
instance of tclsh as where you called "source" from. If you don't
want any effects from a.tcl to remain in the current shell, you
rather do: set retvar [exec tclsh a.tcl]