Running IM from .bat files, some questions

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Running IM from .bat files, some questions

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Running IM from .bat files, some questions

Post 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.
snibgo's IM pages: im.snibgo.com
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Re: Running IM from .bat files, some questions

Post by holden »

Thanks snibgo, really good info as usual!
Post Reply