Tcl fileevent和after在同一事件循环中
要解析日志文件,我想做如下操作Tcl fileevent和after在同一事件循环中,tcl,Tcl,要解析日志文件,我想做如下操作 跟踪文件 一段时间后,编写解析数据并执行其他操作 这是我的(示例)脚本 拖尾工作正常,但未触发之后的脚本 #!/usr/bin/tclsh proc readfile {fd} { global done puts "READ FILE CALLED..." gets $fd line; # Removed 'while' loop here puts "->>>>$line<<<<&l
- 跟踪文件
- 一段时间后,编写解析数据并执行其他操作
之后的脚本
#!/usr/bin/tclsh
proc readfile {fd} {
global done
puts "READ FILE CALLED..."
gets $fd line; # Removed 'while' loop here
puts "->>>>$line<<<<<<<<<"
### Your condition to exit the event handler####
### set done 1; #### Changing 'done' value to 1 after that condition ####
### So that the event handler will exit ####3
}
proc writefile {} {
puts "WRITE FILE CALLED"
puts xxx
flush stdout
}
if {$::argc > 0} {
set fd [open [list | tail --follow=name --retry [lindex $argv 0] 2>@1]]
} else {
set fd stdin
}
after 3000 writefile
fileevent $fd readable [list readfile $fd]
vwait done
close $fd
知道我做错了什么吗?在读取文件
过程中,您在时使用了一个,导致它卡在里面,这就是为什么之后的不会被触发
#!/usr/bin/tclsh
proc readfile {fd} {
global done
puts "READ FILE CALLED..."
gets $fd line; # Removed 'while' loop here
puts "->>>>$line<<<<<<<<<"
### Your condition to exit the event handler####
### set done 1; #### Changing 'done' value to 1 after that condition ####
### So that the event handler will exit ####3
}
proc writefile {} {
puts "WRITE FILE CALLED"
puts xxx
flush stdout
}
if {$::argc > 0} {
set fd [open [list | tail --follow=name --retry [lindex $argv 0] 2>@1]]
} else {
set fd stdin
}
after 3000 writefile
fileevent $fd readable [list readfile $fd]
vwait done
close $fd
#/usr/bin/tclsh
进程读取文件{fd}{
全球完成
放入“读取文件名为…”
获取$fd行;#此处已删除“while”循环
puts“->>>>$line谢谢,我不知道每次有新行可用时都会调用fileevent。如果有多行可用,会发生什么情况?会多次调用readline
还是只读取一行而没有while
循环?@ubi:每次都会调用它。
dinesh@dinesh-VirtualBox:~/pgms/tcl$ ./ubi.tcl
WRITE FILE CALLED
xxx
ubi
READ FILE CALLED...
->>>>ubi<<<<<<<<<
cool
READ FILE CALLED...
->>>>cool<<<<<<<<<
working
READ FILE CALLED...
->>>>working <<<<<<<<<