Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

redirect output of "source a.tcl" to a file

2,750 views
Skip to first unread message

san

unread,
May 15, 2008, 3:29:40 AM5/15/08
to
I need to redirect output of TCL commands to a file. I have been able
to do it by redirecting the command output using ">". Now I am stuck
at source command as it gives me the error
% source a.tcl > a.txt
wrong # args: should be "source fileName"
%

How can I run source command and store its output in a file?

-- San

Andreas Leitgeb

unread,
May 15, 2008, 3:42:34 AM5/15/08
to

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]

0 new messages