Skip to content

Instantly share code, notes, and snippets.

@dertom95
Created January 9, 2019 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dertom95/1b743a05d9b83585386c49b8c94d8ff0 to your computer and use it in GitHub Desktop.
Save dertom95/1b743a05d9b83585386c49b8c94d8ff0 to your computer and use it in GitHub Desktop.
## simple logchecker by dertom and heavy stackoverflowing ;)
## can be used with vanilla python: https://www.python.org/ftp/python/3.7.2/python-3.7.2.exe
## or blender's python: [blender-folder]/2.79/python/bin/python.exe
##
## just call: python.exe logexecuter.py
import time
import subprocess
# the logfile to check
logfile = "./log.txt"
# the work folder where the batch file gets executed
workFolder ="e:\\win"
# the batch filename
batchfile = "e:\\batch2.bat"
# the match to search for
logmatch = "QUIT HERE"
# keep on tracking after match. caution: log-file might be locked and can only deleted if process got quit
breakOnMatch = True
# output log checker
doOutput = False
def follow(thefile):
thefile.seek(0,2)
while True:
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
if __name__ == '__main__':
logfile = open(logfile,"r")
loglines = follow(logfile)
for line in loglines:
if line==logmatch:
p1 = subprocess.Popen([batchfile],cwd=workFolder)
p1.wait()
print("called batch...")
if (breakOnMatch):
break
else:
if doOutput:
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment