Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

FOLDERMONITOR confusions

Dec
238
2
TCC 15.01.52 x64 Windows 7 [Version 6.1.7601]

The documentation for FOLDERMONITOR notes:

For example, to monitor your d:\results directory and copy any new or modified files to a web page:
foldermonitor d:\results created modified forever copy "%%_folderfile1" "http://mycompany.com/results/"


So, to test this in directory C:\MJA\Projects\epub-docs:

foldermonitor C:\MJA\Projects\epub-docs created modified 3 echo modified

I only want to see how this works by having a change to any file in that directory trigger an "echo modified" command. So, in that directory:

echo.>> tempfile.tmp

Nothing happened.

I ran foldermonitor /c to remove all monitoring and then tried again. Maybe an echo command isn't sufficient.

foldermonitor C:\MJA\Projects\epub-docs created modified 3 dir

I modified the tempfile.tmp file -- and nothing happened. No command executed.

Then I tried:

foldermonitor C:\MJA\Projects\epub-docs /i"tempfile.tmp" created modified 3 dir

And modified the file, and nothing happened.

I ran foldermonitor /c again, then set it up again for a larger number of iterations, then repeated some of the aboe steps, and then decided to delete tempfile.tmp to see what would happen.

TCC crashed. I have now been able to repeat this crash by repeating the above steps, including the file-deletion. "TCC.exe has stopped working."

I decided to try it in a different directory, just for sport.

foldermonitor c:\temp /i"temp.tmp" created modified deleted 3 echo help

That file didn't exist. So:

c:\temp> echo.> temp.tmp

This time, the word "help" was echoed to the terminal... and then TCC paused, as if waiting for a keystroke. I pressed ENTER. Then I got the command line back.

Tried a second time. This time "help" was echoed and I was returned to the command line immediately.

Third time: Let's see what happens if I delete temp.tmp

Another crash of the same type. Command processor "has stopped working."

Ok, what am I doing wrong here?
 
FOLDERMONITOR's command is being executed by a different thread, different from the thread that issues the prompt and accepts input. And Windows schedules the threads, not TCC. If the command is executed before the next prompt is issued, it will look normal (you'll get a new prompt). If the next prompt is issued before the command is executed, it won't look normal; you won't see yet another prompt, but you will be on the next command line (you were right, TCC is awaiting input, as it normally does). When this happens you can just press Enter to get a new prompt.

I did manage to get TCC to crash a few times. Below, after FOLDERMONITOR worked correctly a few times, I did "FOLDERMONITOR /C" and started another FOLDERMONITOR. That second one produced **two** "help messages for a while, and then crashed. There does seem to be a bug.
Code:
v:\> foldermonitor v:\ created modified deleted 50 echo help

v:\> echo.>> tempfile.tmp

←[32;1v:\> elp
echo.>> tempfile.tmp

help
v:\> echo.>> tempfile.tmp

help
v:\> echo.>> tempfile.tmp

help
v:\> echo.>> tempfile.tmp

help
v:\> foldermonitor /c

v:\> foldermonitor v:\ created modified deleted 50 echo help

v:\> echo.>> tempfile.tmp

help
v:\> echo.>> tempfile.tmp

help
←[32;1v:\> elp
echo.>> tempfile.tmp

help
help
v:\> echo.>> tempfile.tmp

help
help
v:\> echo.>> tempfile.tmp

help
help
v:\> echo.>> tempfile.tmp

help
help

CRASH
 
Instead of using echo , maybe use msgbox or statusbar if you want text to display with foldermonitor.

Joe
 
Nice tutorial! I see a simplification of the example, showing off even more TCC features - use the MOVE command instead of COPY and DEL. esp. with the /V option; this also permits dropping the command group parentheses.
 
Thanks for your help, folks -- and thanks for pointing out the tutorial. What I had hoped to do is to have the monitoring wait for an update to an .EPUB file I'm creating in Sigil. When the file is saved: run the source-control program (hg.exe -- Mercurial) and check in an update to the depot. Or maybe have this happen with every other save, perhaps by having a .btm file that runs (triggered by FOLDERMONITOR) after a save tweak an environment variable (if 0, do nothing and set variable to 1; if 1, check in the file and reset variable to 0...something like that). Not sure if, given the threading, having the monitor launch a .btm file is a good idea, though -- what happens to the environment when the new thread is run?

The crash worries me. I don't know if this approach is reliable. Guess I'd best try it for a while in some 'scratch' directory first.
 
The TCC process has one environment which is seen by all threads.
 
Due to my ignorance of how "modification" is detected, I would worry about that a slow modification of the .EPUB file would trigger activity more than once while the updating takes place. Otherwise your concept seems perfectly feasible. On occasion I use a similar method to trigger analysis and file system updating when detecting clipboard change. Needed when websites provide updated information only for viewing, not for saving.
 

Similar threads

Back
Top