There is some (compiled and not my) program A, which starts .log file from the beginning each time, when I launch it. And I wrote the program B to work with this log using this approach:
File.open("qconsole.log") do |log|
log.gets nil # I am interested only in new lines
loop do
next sleep 0.1 unless line = log.gets
line.chomp!
puts line
# some code
end
end
For example, after two new lines in the .log file I see this output:
player1: i talk blabla
player2: no way!
But when I quit and restart the program A:
]\quit
----- Server Shutdown -----
==== ShutdownGame ====
AAS shutdown.
---------------------------
----- CL_Shutdown -----
RE_Shutdown( 1 )
Shutting down OpenGL subsystem
...wglMakeCurrent( NULL, NULL ): success
...deleting GL context: success
...releasing DC: success
...destroying window
...shutting down QGL
...unloading OpenGL DLL
-----------------------
the program B seems to lose the .log file after this. It doesn't print me new lines anymore. I suppose, it gets eternal nil
from log.gets
.
So how can I know, that I need to stop doing log.gets
and reopen the .log file?
UPD: Windows 7