I am currently writing IM commands to .bat files which then get run when they appear in a folder, I would like to know how to do a couple of things.
Is there a way to know when IM is done writing the images so that the next (non-IM) command can proceed safely, or is this something done automatically when bat files are ran?
Is there a way to limit the instances of IM that can run at the same time, so if eg. 5 bat files drop into the folder only 2 will run?
Thanks!
Running IM from .bat files, some questions
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Running IM from .bat files, some questions
When the bat file runs, each command will finish before the next one starts (unless you do something weird, like using "start" on each command).holden wrote:Is there a way to know when IM is done writing the images so that the next (non-IM) command can proceed safely, or is this something done automatically when bat files are ran?
That's called an inter-process lock. There are many ways to do this. A simple method: each bat file, when it starts work, creates a named file in a special directory. When it finishes, it deletes that file. Before it starts work, it counts how many files are in the directory. If there are two or more, it waits until there are less than two, or exits with an error, or whatever you want.holden wrote:Is there a way to limit the instances of IM that can run at the same time, so if eg. 5 bat files drop into the folder only 2 will run?
That simple method is only approximate because counting the files and creating a new file should be an atomic process. But it may be good enough.
snibgo's IM pages: im.snibgo.com
Re: Running IM from .bat files, some questions
Thanks snibgo, really good info as usual!