Page 1 of 1

Command line - "Convert" - what is the return code?

Posted: 2012-03-16T00:50:43-07:00
by splee
I am using LabVIEW command shell to execute the command line:
cmd /c convert -depth 8 -size 1500x13000 -density 800 gray:54_3.dat c:\Print_Quality_Project\VB_Test\54_3.jpg
and I got a return code of 1.
How do I find out what this return code means?

Re: Command line - "Convert" - what is the return code?

Posted: 2012-03-18T02:39:31-07:00
by Bonzo
I think 0 is success and 1 is fail.

Re: Command line - "Convert" - what is the return code?

Posted: 2012-03-18T19:28:35-07:00
by splee
Bonzo wrote:I think 0 is success and 1 is fail.
But I do get return code of "4"..
Where can i find the source code for the command line tool, so that I could check all the return codes?

Re: Command line - "Convert" - what is the return code?

Posted: 2012-03-18T21:09:06-07:00
by anthony
splee wrote:Where can i find the source code for the command line tool, so that I could check all the return codes?
You asked for it!!!

The command 'main()' function is in "utilities/convert.c" Though in IMv7 that is being obsoleted for "utilities/magick.c".

This module is however simple a call to a 'wrapper' library function MagickCommandGenesis() which is used for some special options, such as "-bench" (process command multiple times reporting timings), but then that function forwards to the actual 'command' function that was given as a argument to MagickCommandGenesis().

For "convert" that function is ConvertImageCommand() and is located in "wand/convert.c". This is the function that does the task of actually figuring out how to process the argument array given.

Here is an example of calling this function directly...

Code: Select all

/*
   Bare minimal test of a direct call to ConvertImageCommand()
   Actually this is basically what the "convert" command does.

   Compile with...
     gcc -I/usr/include/ImageMagick -lMagickWand -lMagickCore \
         convert_equiv.c -o convert_equiv

*/
#include <stdio.h>
#include "magick/studio.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "wand/MagickWand.h"
#include "wand/convert.h"

int main(int argc, char **argv)
{
  MagickCoreGenesis(argv[0],MagickFalse);

  {
    int arg_count;
    char *args[] = { "program_name", "-size", "100x100", "xc:red",
                     "(", "rose:", "-rotate", "-90", ")",
                     "+append", "show:", NULL };

    for(arg_count = 0; args[arg_count] != (char *)NULL; arg_count++);

    ImageInfo *image_info = AcquireImageInfo();
    ExceptionInfo *exception = AcquireExceptionInfo();

    MagickBooleanType status =
       ConvertImageCommand(image_info, args_count, args, NULL, exception);

    if (exception->severity != UndefinedException)
    {
      status=MagickTrue;
      CatchException(exception);
    }

    if (status == MagickFalse)
      fprintf(stderr, "Error in call\n");

    image_info=DestroyImageInfo(image_info);
    exception=DestroyExceptionInfo(exception);
  }
  MagickCoreTerminus();
}

The function itself is however not straight forward and complex code due to the need to handle IMv5 Legacy handling. The bulk of the function can also be ignored to an extent as it simply contains syntax checking. The actual read operation code (in IMv6) is in "wand/mogrify.c" and is called using the FireImageStack() macro. -- I did say it was complex!


IMv7 "magick" on the other hand is much more straight forward. No 'macro' code, that hides alot of the processing. Its functions (in "MagicWand/magick-cli.c") first handle 'special' requirements (eg "-version" "-list" "-script" otpions) then calls either a ProcessCommandOptions() or a ProcessScriptOptions() to handle options from a argument array (command line) or from a file stream (script). It calls the appropriate functions in "MagickWand/operation.c" to actually process the options in terms of a special MagickWand structure.

This install handling is 'mostly settled' but could still have some changes as development proceeds. IMv7 handling will replace the old IMv6 option handling. And "magick" command replaces "convert".

Re: Command line - "Convert" - what is the return code?

Posted: 2012-03-19T01:08:00-07:00
by whugemann
I think that the actual value of the return code is of little help for your error diagnosis, see http://www.imagemagick.org/Usage/windows/#debugging. Instead, you should test your command line in a DOS box thoroughly before you launch it by another program. Please note that you don't need the cmd overhead in your example, a simple

Code: Select all

convert -depth 8 -size 1500x13000 -density 800 gray:54_3.dat c:\Print_Quality_Project\VB_Test\54_3.jpg
would do just as well.
I though have to admit that I don't really understand what you are actually trying to do in this command line...