Basic Wndows scripting problem

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
chris-zwarg
Posts: 5
Joined: 2016-02-05T07:05:58-07:00
Authentication code: 1151

Basic Wndows scripting problem

Post by chris-zwarg »

Hello, I have recently installed IM and it is working as described from the command-line.

However I am completely stumped how to invoke IM from a Windows .bat script, and I am sorry to say I do not find a (to me) comprehensible and straightforward tutorial anywhere. Please forgive my probably stupid newbie question.

I started experimenting by simply putting the two well-known lines of code to test whether IM is working into a .bat file:

convert wizard: wizard.png
imdisplay wizard.png
pause


When I execute this .bat no "wizard.png" is created nor displayed. In addition it throws several errors (error descriptions in German since that's the language of my OS):

first line of code: "Unzulässiger Parameter: wizard.png" (parameter "wizard.png" not allowed)
second line: "Der Befehl "imdisplay" ... konnte nicht gefunden werden" (no such command as "imdisplay")

Another attempt was a simple one-line script where one _should_ be able to drag-and drop an image and have it converted to .png format in the same folder:

convert %1 "%~dpn1.png"

This throws similar strange errors, note especially the DIRECTORY invoked in the cmd window (what has MAPI to do with IM?)

C:\Programme\Gemeinsame Dateien\System\Mapi\1031\NT>convert H:\Import\sample.jpg
"H:\Import\sample.png"
Unzulässiger Parameter - "H:\Import\sample.png"

I suspect the machine does not use IM's "convert" but another eponymous routine in the MAPI folder, but why? the MAPI\1031\NT directory is not even part of my Windows Path!!

Thank you very much for yor kind attention and help.

Chris
chris-zwarg
Posts: 5
Joined: 2016-02-05T07:05:58-07:00
Authentication code: 1151

Re: Basic Wndows scripting problem

Post by chris-zwarg »

PS: I have already tried the suggestion given in another thread, renaming IM's "convert.exe" to "imconvert.exe" to circumvent the apparent conflict with another (MAPI) function "convert", but it doesn't help. Nor did deinstalling and re-installing IM, I have tried both the "static" and "dynamic" variants. When I rename "convert.exe" to "imconvert.exe" and correspondingly call "imconvert" from the script, I get a different error, namely that this function does not exist, just like it also claims "imdisplay" doesn't exist. This still from the "...\MAPI\..." directory, for which the error messages, strictly speaking, are of course correct! How do I force the script to use (like an ordinary cmd window does) the ImageMagick directory as source for the IM functions?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Basic Wndows scripting problem

Post by snibgo »

If those commands work when typed at the command line, they should also work when put in a filed called, say "imtest.bat", by typing...

Code: Select all

imtest.bat
... at the command line.

Try the command:

Code: Select all

where convert.exe
What does that say? On my computer, it says:

Code: Select all

C:\cygwin64\bin\convert.exe
C:\Windows\System32\convert.exe
So the program in C:\cygwin64\bin\ will be run, not the one in C:\Windows\System32\.

What version of Windows are you on?
snibgo's IM pages: im.snibgo.com
chris-zwarg
Posts: 5
Joined: 2016-02-05T07:05:58-07:00
Authentication code: 1151

Re: Basic Wndows scripting problem

Post by chris-zwarg »

WinXP SP 3

My machine doesn't recognize a command "where", neither from the cmd nor from the batch. Your code gives just that error message, sorry.
chris-zwarg
Posts: 5
Joined: 2016-02-05T07:05:58-07:00
Authentication code: 1151

Re: Basic Wndows scripting problem

Post by chris-zwarg »

The usual DOS commands like dir, cd,.. work however so cmd.exe is reponsive. But no "where"!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Basic Wndows scripting problem

Post by snibgo »

Your Windows is older than mine. Perhaps it doesn't have "where".

At http://www.imagemagick.org/script/binar ... hp#windows, it says:
If you have any problems, you likely need vcomp120.dll. To install it, download Visual C++ 2013 Redistributable Package.
Have you tried that?
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Basic Wndows scripting problem

Post by GeeMack »

chris-zwarg wrote:How do I force the script to use (like an ordinary cmd window does) the ImageMagick directory as source for the IM functions?
You may just need to add the ImageMagick directory to your PATH. Check that by entering the command "path" at the command line. If you don't see an ImageMagick directory in the output, that's your problem. You can fix it pretty easily. There are a couple ways to do it...

You can modify the system PATH by following the instructions on THIS PAGE. Make sure you put the ImageMagick directory at the beginning of the PATH or you may still have a problem because of calling the Windows "convert.exe" command instead of the ImageMagick command. Also make sure you use a semi-colon ";" between each entry in the PATH list.

Or you can modify the PATH in the batch file so it only gets used during each run of the script. You can do that by adding a couple lines of code to your batch file somewhere before the ImageMagick commands. That would look something like this...

Code: Select all

setlocal

path c:\Program Files\ImageMagick;%PATH%
Then continue with the rest of the commands in your script. Make sure you specify exactly the full path to the directory containing your ImageMagick commands.
chris-zwarg
Posts: 5
Joined: 2016-02-05T07:05:58-07:00
Authentication code: 1151

Re: Basic Wndows scripting problem

Post by chris-zwarg »

Thank you so much, your last suggestion did the trick! No idea what must have happened to my Windows installation at some point, but on my machine the PATH as defined and visible in the Environment Variables, and as displayed by typing "path" at command-line, is _not_ identical with the one used by the batch. The latter lacks not only IM, but several other directories/applications as well (which I never noticed before since I never used them in batch scripts). Redefining the path in the script helps. Again, thank you for quick and effective support!!!
Post Reply