Let a .bat sleep in the background untill event occurs

April 27, 2012 at 12:58:18
Specs: Windows XP
Hi All,

This is what I would like to achieve: I have a piece of software that stores logfiles in random amounts of time (you never know when) in a directory. Now what I would like to achieve is writing a .bat file that keeps running in the background and keeps monitoring this directory. Then, when a new logfile gets created, it must open this file immediately (i.e: the latest file, or in other words the file with the most recent modify timestamp)

Does anyone know how to do this? I already achieved to open the most recent file but then I have to keep running the .bat file over and over again. I want to automate this process, so when a new file gets created, it opens it automatically.

Thanks in advance for your help.


See More: Let a .bat sleep in the background untill event occurs

Report •

#1
April 27, 2012 at 23:27:11
As far as I know, you can't "sleep" a batch file. The only way to achieve this would be two have a batch file running indefinitely, which would hog memory on your computer.

Can I put a question here?


Report •

#2
April 28, 2012 at 07:36:00
If you want a script to lie in wait, then you need to pick a language that allows it. VBScript is the native option for WinXP, and as it turns out, I have an example of such a script using VBScript and WMI.

How To Ask Questions The Smart Way


Report •

#3
May 3, 2012 at 23:09:38
batch is power, To do a false sleep try add a PING to localhost and set -n = time to wait in seconds, then declare a goto to te label that points to the scann of log files.
Ej:

:SCAN
PUT YOUR CODE HERE

PING -n 15 127.0.0.1
rem last line wait 15 seconds
goto SCAN
:END


if you can make a flag file "FLAG.TXT" after log file is created to avoid work with the log file while is created and not ready for process it, the code culd by as next:


@ECHO OFF
ECHO WAITING FOR FLAG...
:SCAN
IF EXIST FLAG.TXT GOTO DOIT
GOTO FAKEW
:DOIT
ECHO [%DATE% -%TIME%] PROCESSING LOG FILE...
ECHO [%DATE% -%TIME%] PROCESSING LOG FILE...>>WORLKLOG.TXT
DEL FLAG.TXT
REM "REPLACE THIS ENTIRE LINE WITH YOUR CODE"
:FAKEW
PING -n 5 127.0.0.1>NUL
rem last line wait 5 seconds
goto SCAN
:END


Report •
Related Solutions


Ask Question