Page 1 of 1
Running IM from .bat files, some questions
Posted: 2017-03-22T05:50:33-07:00
by holden
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!
Re: Running IM from .bat files, some questions
Posted: 2017-03-22T08:41:15-07:00
by snibgo
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?
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 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'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.
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.
Re: Running IM from .bat files, some questions
Posted: 2017-03-22T09:35:14-07:00
by holden
Thanks snibgo, really good info as usual!