问题描述
使用,您可以获取并设置频道选项。 -缓冲
指定缓冲的类型,默认情况下,对于 stdin,它为
line
。 code>。
With fconfigure
you can get and set channel options. -buffering
specifies the type of buffering, and by default it is line
for stdin
.
是否可以检查 stdin
处的缓冲区是否为空?
Is there a way to check if the buffer at stdin
is empty or not?
请参阅以下问题:
推荐答案
很显然,您可以将通道模式设置为非阻塞并从中读取。如果读取返回0长度,则无可用。但是,我怀疑您的意思是要测试是否存在数据,但鉴于提到的行缓冲在那里,它不是完整的行。 fblocked命令为此测试一个通道。有关详细信息,但有关缓冲行的信息,请参见。
Obviously you could set the channel mode to non-blocking and read from it. If the read returns 0 length then nothing was available. However, I suspect you mean to test for data present but not a complete line given your mentioning of the line buffering there. The fblocked command tests a channel for this. See fblocked(1) for the details but for a line buffered channel this lets you know that an incomplete line is present.
读取标准输入时的另一个有用命令(如果要读取交互式脚本命令)是使用info complete命令。这样,您就可以累积行,直到info complete返回true为止,然后在一个缓冲区中评估整个缓冲区。
Another useful command when reading stdin, if you are reading interactive script commands is to use the info complete command. With this you can just accumulate lines until info complete returns true then evaluate the whole buffer in one.
这篇关于如何检查TCL的stdin缓冲区是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!