gpt4 book ai didi

tcl - 在 tcl 中读取缓冲流

转载 作者:行者123 更新时间:2023-12-04 18:12:02 24 4
gpt4 key购买 nike

这是一个关于 tcl 文件读取的问题。
我正在打开一个缓冲流来写入,我只有一个文件处理程序引用它
现在,在逐行读取此缓冲区时,在某些情况下,我必须将缓冲区的所有内容都放入,请建议我如何实现这一点。
所以我只是粘贴一个示例代码来解释我的要求。

catch { open "| grep" r } pipe
while { [gets $pipe line] } {
if { some_condition } {
## display all the content of $pipe as string
}
}

谢谢
汝池

最佳答案

要从管道读取直到它被另一端关闭,只需使用 read $pipe .然后,您可以这样做:

set pipe [open "| grep" r]
while { [gets $pipe line] >= 0 } { # zero is an empty line...
if { some_condition } {
puts [read $pipe]
### Or, to include the current line:
# puts $line\n[read $pipe]
}
}

如果您想要管道输出中早期的任何内容,则必须将其保存在变量中。

关于tcl - 在 tcl 中读取缓冲流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12424622/

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