Capture return value from Compare tool in Visual Basic

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
IMbatchprogrammer
Posts: 2
Joined: 2013-04-16T07:31:40-07:00
Authentication code: 6789

Capture return value from Compare tool in Visual Basic

Post by IMbatchprogrammer »

Hi,

I'm trying to use VBA for Excel to compare image files and write the comparison response back to an Excel cell.

The relevant piece of code here is:
retcode = img.Compare("verbose", "-metric", "rmse", first_file , second_file, "null:")
I know the code works, as I've tested it with the addition of an output comparison file paramter which worked fine, giving an output file. It also works file in the command line prompt, giving a compaison value.

However, the problem is that the return code retcode is coming back as blank. In other words I'm capturing the error code, which is blank as the command works ! ! ! !

What I want is not the error return code, but the comparison value returned from the tool - the value you get when you run it from the command line.

Thanks in advance
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Capture return value from Compare tool in Visual Basic

Post by snibgo »

The comparison value goes to stderr. You need some way of capturing stderr from Visual Basic. I don't know what that method is.
snibgo's IM pages: im.snibgo.com
IMbatchprogrammer
Posts: 2
Joined: 2013-04-16T07:31:40-07:00
Authentication code: 6789

Re: Capture return value from Compare tool in Visual Basic

Post by IMbatchprogrammer »

Thanks for the idea. That helped me out, and I started looking into capturing STDERR in VBA. Using the 1>2 command in DOS or 2>&1 enables the reponse to be directed.

Infact I was using NULL: as a parameter and 2>OutputResult.txt and that worked well creating a file with OutputResult.txt from DOS. THis would work fine as I could write VB code to look at the OutputResult.txt file and get the number out.

However I cannot translate this DOS command into VB code. The function just doesn't run.

i.e.

Code: Select all

compare -metric "rmse" file_1 file_2 null: 2>outputresult.txt
in DOS works putting result in outputresult.txt
BUT

Code: Select all

result = img.Compare ("-metric", "rmse", "file_1", "file_2", "null:", "2>outputresult.txt ")
DOESN'T even run!

Any other ideas?

Thanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Capture return value from Compare tool in Visual Basic

Post by anthony »

The second probably is executing the command, bypassing DOS.

I can nto however help with a solution for the second command (I am not a windows/dos user)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply