【问题标题】:How to log xterm window from tcl script如何从 tcl 脚本记录 xterm 窗口
【发布时间】:2014-04-05 17:09:00
【问题描述】:

我正在通过exec xterm -geometry 78x36+0+0 -fn "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1" -sl 10000 -sb -bg white -bd white -into.... 从我的 tcl 打开一个 xterm 窗口。我正在这个仿真终端上执行其他命令。现在我想将这些命令的输出记录到来自同一个 tcl 脚本的文件中。 任何人都可以知道如何做到这一点....?

提前致谢 壁画克里希纳

【问题讨论】:

    标签: linux terminal tcl xterm terminal-emulator


    【解决方案1】:

    从外部捕获 - 从执行 exec xterm … -into … 的脚本的角度来看 - 非常困难,因为在子窗口上绘制某些内容时您不会收到任何事件(除非您实际上不想要它们)你最终只会看到很多关于发生的事情的位图;大而且信息量不大。您需要使用不同的方法;您需要从内部捕获,以记录用户在终端上看到的内容。幸运的是,这实际上并不难做到。

    要完整记录终端内发生的事情(终端程序本身不提供该功能),最好的办法是在终端内运行一个小小的 Expect 脚本。

    package require Expect
    
    log_file /tmp/somefile.log
    spawn $env(SHELL)
    interact
    exit
    

    在终端内部运行这个(xterm 有一个选项可以做到这一点),它会记录里面发生的一切。它记录在一个临时文件/tmp/somefile.log 中,但您可以根据需要更改要使用的名称。通过参数传入日志文件可能是个好主意:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2016-09-16
      相关资源
      最近更新 更多