Page 1 of 1

Capture return value from Compare tool in Visual Basic

Posted: 2013-04-16T07:39:58-07:00
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

Re: Capture return value from Compare tool in Visual Basic

Posted: 2013-04-16T08:04:03-07:00
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.

Re: Capture return value from Compare tool in Visual Basic

Posted: 2013-04-16T10:08:32-07:00
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

Re: Capture return value from Compare tool in Visual Basic

Posted: 2013-04-16T20:04:43-07:00
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)