Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirecting stdout

Status
Not open for further replies.

tmccann2

Technical User
Feb 13, 2003
1
US
Hello:

Within a tcl script, I'm sourcing another tcl script. I'm trying to redirect the output of the sourced tcl script to a file. Here is the code I've written to attempt this:

set fd [open $OutFileName a]
puts $fd [source Master.tcl]
close $fd

OutFileName has been defined eariler in the program. When I run this, OutFileName is created, but the output goes to stdout and not OutFileName.

Any ideas as to what I am doing wrong? Thanks in advance.

Tom
 
I think you have to read your source file line by line (using the gets command), then writing (puts) to your target file.

my understanding is that the source command is intended for multifile code, not for in/out between files.

good luck.

Jorge Moreno
 
jicote is mostly correct.
try read instead.

proc OpenCopyandSource {ffile sfile} {
set fd [open $ffile w]
set fd2 [open $sfile r]

if {![catch {puts $fd [read $fd2]} err_puts]} {
close $fd
close $fd2
source $sfile
return 1
}
error $err_puts
return 0
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top