TCL 8.5 TEE

问题描述 投票:0回答:1

我有一个来自 Schelte Bron 的 Tee 程序,在 TCL 8.6 中运行良好,但是,我正在尝试调整我们的脚本以与使用 TCL 8.5 的 EDA 工具 (Xilinx 2023.02) 配合使用。当我尝试 8.5 中的代码时出现错误。关于 8.5 语法的任何建议:

namespace eval tee {
    variable methods {initialize finalize write}
    namespace ensemble create -subcommands {replace append channel} \
      -unknown [namespace current]::default
    namespace ensemble create -command transchan -parameters fd \
      -subcommands $methods
}

proc tee::default {command subcommand args} {
    return [list $command replace $subcommand]
}

proc tee::channel {chan fd} {
    chan push $chan [list [namespace which transchan] $fd]
    return $fd
}

proc tee::replace {chan file} {
    return [channel $chan [open $file w]]
}

proc tee::append {chan file} {
    return [channel $chan [open $file a]]
}

proc tee::initialize {fd handle mode} {
    variable methods
    return $methods
}

proc tee::finalize {fd handle} {
    close $fd
}

proc tee::write {fd handle buffer} {
#    puts -nonewline $fd $buffer
    # Remove Null and change crcrlf to crlf
    puts -nonewline $fd [regsub -all \r\n [regsub -all \x00 $buffer ""] \n]
#    return [regsub -all {<[^>]*>} $buffer ""]  ;# this works for ModelSim batch but not GHDL
    return $buffer
}

我通过调用 StartTranscript 来启动脚本:

proc StartTranscript {FileName} { 

    set LogFile  [open ${FileName} w]
    tee channel stderr $LogFile
    tee channel stdout $LogFile
}

并通过调用 StopTranscript 来结束它:

proc DefaultVendor_StopTranscript {{FileBaseName ""}} {
    flush stdout
    chan pop stdout
    chan pop stderr
  }
}

如果有更简单的方法来做到这一点,我也愿意。我需要做的就是将发送到 stdout 或 stderr 的所有内容捕获到日志文件中。

不幸的是,当前的解决方案使用的代码需要 TCL 8.6,我不确定我可以删除什么,不能删除什么。

tcl
1个回答
0
投票

8.5 中没有

chan push
;这是在 8.6 中添加的。底层的可堆叠转换系统就在那里(它在那里启用诸如 TLS 套接字扩展之类的功能),但它不会导出到脚本。

您可以编写一些 C 代码来实现转换并将其连接起来(不是我熟悉的 API 的一部分),或者在您的情况下,事情足够简单,您可以将转换放在单独的进程中,这可以是一个简单的 Tcl 脚本,用于处理二进制数据输入和二进制数据输出。

或者您使用

chan create

(如果我正确阅读文档,它是在 8.5 中添加的)并进行实现重定向写入。

© www.soinside.com 2019 - 2024. All rights reserved.