1

I have a Windows program that outputs log file. I need to create a batch file that instantly detects theses words "processing ended". How do I do it?

Marcin
  • 11
  • 1
  • with `instantly` you mean: "while the program is still logging"? Won't it end, once it told you "processing ended"? – Stephan Mar 27 '17 at 16:43
  • It can be done by powersheell, check this topic http://stackoverflow.com/questions/17238366/powershell-searching-for-a-part-of-a-string-in-a-logfile – Mihail Kuznesov Mar 27 '17 at 16:53
  • "Instantly" could be a problem, by my experience windows console program output lines into stdout when it finish its job. Trying something similar with 'tail.exe -f' program inside FOR loop, but FOR loop print nothing until tail.exe terminate, than print everything at one time. – user2956477 Mar 27 '17 at 17:23
  • Does not have to be instant. 10 seconds will be enough. – Marcin Mar 27 '17 at 20:08

1 Answers1

0

Your "immediately" requirement is a bit vague to me. Immediately after it wrote the line? Immediately after the process ended? Immediately after the log file was closed? How will your system know the log file is ready to be read?

Here is something that will

  • reads every *.msg in c:\temp
  • it does so /Recursively.
  • The command is looking for error:, yours would be looking for processing ended
  • and when it finds a hit, it >>(aka writes) the whole line %%b in a report file c:\temp\myreport.log, though yours could trigger whatever you want.

    for /R "c:\temp" %%a in (.msg) do ( for /f "skip=2 tokens=" %%b in ('find /I "error:" "%%a"') do ( echo %%b >>"c:\temp\myreport.log" ) )

Now that you have something to read and act on the log... I think you need to address the timing question. What's triggering the application in the first place? Are you in control of that code? Can you piggyback some type of trigger on that?

blaze_125
  • 2,262
  • 1
  • 9
  • 19
  • Yes, it is Leea Go engine (sjeng.org). I am not in control of the code. – Marcin Mar 27 '17 at 20:07
  • Let me rephrase my question, There is a log file "output.log". It is growing and at a certain point, the line has certain words, I need to know when it happens. – Marcin Mar 27 '17 at 22:40
  • Or better would be just to pipe the Leela Go engine console output. The action would be to kill the engine, so it will prevent next game to start. "Game ended" is the exact string that should trigger action. – Marcin Mar 28 '17 at 14:01