TCL:无按键时循环
我想运行一个 while 循环,直到 stdin 充满一个字符。
puts "Press x + <enter> to stop."
while {[gets stdin] != "x"} {
puts "lalal"
}
上面代码的问题是它将等待 stdin
而我不希望它等待。我希望代码始终被执行。
编辑 2011 年 9 月 8 日 - 上午 8.55
代码在名为 System Console (Altera) 的 FPGA 工具中使用。这确实适用于 TCL 命令,但不幸的是我不知道它可以处理哪些命令,不能处理哪些命令。
I would like to run a while
loop until the stdin
is filled with a character.
puts "Press x + <enter> to stop."
while {[gets stdin] != "x"} {
puts "lalal"
}
The problem with the code above that it will wait for stdin
and I don't want it to wait. I want the code to be executed all the time.
Edit 8th September 2011 - 8.55am
The code is used inside a FPGA tool called System Console (Altera). This does work with TCL Commands, but unfortunately I don't know which it can handle and which it doesn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在 stdin 上使用 fileevent 设置一个在通道变得可读后调用的函数,然后使用 vwait 运行事件循环。您可以使用后链来启动其他任务,以分段完成工作,而无需停止事件处理太长时间。
You should use a fileevent on stdin to set a function to be called once the channel becomes readable then use vwait to run the event loop. Your other tasks can be launched using after chains to have work done in pieces without halting the event processing for too long.
如果将
stdin
通道置于非块模式,则gets stdin
将返回空字符串(并且fblocked stdin
将能够当输入不可用时返回1
),而不是等待某些事情发生。事实上,你还可以使用系统
stty
程序来做甚至更奇特的事情。If you put the
stdin
channel into non-block mode, thegets stdin
will return the empty string (andfblocked stdin
will then be able to return1
) when input is not available, instead of waiting for something to happen.In fact, you can also use the system
stty
program to do even more fancy things.