0

I am opening a xterm window from my tcl by exec xterm -geometry 78x36+0+0 -fn "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1" -sl 10000 -sb -bg white -bd white -into..... I am executing other commands on this emulate terminal. Now i want to log output of those commands into a file from the same tcl script. Can any one have idea about how to do it.... ?

Thanks in advance murali krishna

mkreddy
  • 163
  • 3
  • 5
  • 12

1 Answers1

0

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
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215