how can I redirect a proc output into a file in tcl, for example, I have a proc foo, and would like to redirect the foo output into a file bar. But got this result
At present when you type foo > bar Tcl is trying to run a foo proc that takes 2 parameter, as this doesn't exist you get the error message. I can think of two ways you could tackle this problem.
You can redirect at the top level, so when you run tclsh tclsh > bar then all of the output will be redirected, however I doubt this is what you want.
You could change foo so that it accepts an open file as a parameter and write to that:
proc foo {fp} {
puts $fp "some text"
}
set fp [open bar w]
foo $fp
close $fp