Capturing from outside — from the perspective of the script doing exec xterm … -into …
— is extremely hard, as there are no events you get when something draws on the subsidiary window (except in one case where you actually don't want them) and you'd end up just seeing a lot of bitmaps of what happened anyway; large and really uninformative. You need to use a different approach; you need to capture from the inside, to log the things that the user sees on the terminal. Fortunately, this isn't actually too hard to do.
To keep a complete log of what happens inside a terminal (where the terminal program itself doesn't offer the feature) your best bet is to run a little Expect script inside the terminal.
package require Expect
log_file /tmp/somefile.log
spawn $env(SHELL)
interact
exit
Run this inside the terminal (there's an option to xterm to do this) and it will record everything that happens inside. It's logged to a temporary file, /tmp/somefile.log
, but you can change what name to use if you desire. It's probably a good idea to pass the log file in by an argument:
package require Expect
if {$argc < 1} {
error "not enough arguments"
}
# Unlike C, Tcl doesn't include interpreter name or script name in argv
log_file [lindex $argv 0]
spawn $env(SHELL)
interact
exit