我可以在Tcl中找到文件句柄中的文件名吗?

And*_*ong 4 filenames file tcl channel filehandle

类似于我可以在Perl中找到文件句柄中的文件名吗?但在Tcl.

我计划缓存filename-filehandle关联,所以我纯粹是出于好奇 - 特别是链接中提到的"操作系统魔法".在Tcl中有可能吗?

如果重要的话,我(强制进入)在SunOS 5.10上使用Tcl 8.0.5.

Don*_*ows 5

有了旧的Tcl版本,你真的没有那么多的选择.最简单的是做一点包装openclose:

rename open _original_open
rename close _original_close

proc open {filename args} {
    global fileForChannel
    set channel [eval [list _original_open $filename] $args]
    set fileForChannel($channel) $filename
    return $channel
}
proc close {channel} {
    global fileForChannel
    catch {unset fileForChannel($channel)}
    _original_close $channel
}
Run Code Online (Sandbox Code Playgroud)

然后,您$ch只需阅读就可以获得开放频道的文件名$fileForChannel($ch).