gpt4 book ai didi

file - 我可以从 Tcl 中的文件句柄中找到文件名吗?

转载 作者:行者123 更新时间:2023-12-05 00:35:24 26 4
gpt4 key购买 nike

类似于 Can I find a filename from a filehandle in Perl?但在 Tcl 中。

无论如何,我计划缓存文件名 - 文件句柄关联,所以我纯粹是出于好奇而询问 - 特别是链接中提到的“操作系统巫术”。在Tcl中可能吗?

如果重要的话,我(被迫)在 SunOS 5.10 上使用 Tcl 8.0.5。

最佳答案

使用那么旧的 Tcl 版本,您真的没有那么多选择。最简单的就是对open做一点包裹。和 close :

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
}

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

关于file - 我可以从 Tcl 中的文件句柄中找到文件名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9486361/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com