Page 1 of 1

java waitfor() never returns when warnings occur

Posted: 2010-10-27T14:11:56-07:00
by tms
I've found that when I shell out from java to execute imageMagick convert.exe, it will never return a 'process complete' state to the java Process.waitfor() method whenever warnings occur.

For example, if I exec the command line:

Code: Select all

"c:\Program Files\ImageMagick\convert.exe" 
  +matte -gravity Center -thumbnail 100x100 -density 72 -background white -extent 100x100 
  "C:\ingest\VRUpload\ag-obj-241-014-mas.tif" 
  "C:\ingest\thumbs\ag-obj-241-014-mas.jpg"
I'll get:

Code: Select all

convert.exe: C:\ingest\VRUpload\ag-obj-241-014-mas.tif: wrong data type 7 for "XMLPacket"; tag ignored. `TIFFReadDirectory' @ tiff.c
/TIFFWarnings/546.
convert.exe: C:\ingest\VRUpload\ag-obj-241-014-mas.tif: wrong data type 7 for "RichTIFFIPTC"; tag ignored. `TIFFReadDirectory' @ tif
f.c/TIFFWarnings/546.
convert.exe: C:\ingest\VRUpload\ag-obj-241-014-mas.tif: wrong data type 7 for "Photoshop"; tag ignored. `TIFFReadDirectory' @ tiff.c
/TIFFWarnings/546.
convert.exe: C:\ingest\VRUpload\ag-obj-241-014-mas.tif: unknown field with tag 37724 (0x935c) encountered. `TIFFReadDirectory' @ tif
f.c/TIFFWarnings/546.
Which are valid warnings for that particular file. The problem is that if I shell out of java with that same command it will just hang, even though the process has actually completed. I.e. it's as though convert.exe is still running (as far as java is concerned).

For what it's worth, my java looks like:

Code: Select all

    Process proc = null;
    try 
    {
      proc = Runtime.getRuntime().exec(command);
    } 
    catch (IOException e) 
    {
      throw new MediaToolsException("IOException while trying to execute: " + command + "\n"+e.getMessage());
    }

    while (true) 
    {
      try 
      {
        proc.waitFor();   // This line just hangs forever when those warnings occur.
        break;
      } 
      catch (java.lang.InterruptedException e) 
      {
        throw new MediaToolsException("IngestUtils.exec: Process interrupted while trying to execute: " + command);
      }
    }
What I've discovered as a workaround is that by adding the -quiet switch the problem goes away. The process returns normally and everything works properly.

So I guess my question is - is this a bug? Frankly I'm more concerned about the java side than imageMagick, but I'm wondering what the process could be doing to cause this behavior, and whether there's a way to detect this?
Thanks in advance,
Tim

Re: java waitfor() never returns when warnings occur

Posted: 2010-10-27T18:09:02-07:00
by anthony
I have no idea why java is hanging.

However you should read your image BEFORE trying to use processing options on it.
Your using a legacy option handling capability that may disappear at some point.

Re: java waitfor() never returns when warnings occur

Posted: 2010-10-28T10:11:54-07:00
by tms
anthony wrote:However you should read your image BEFORE trying to use processing options on it.
Your using a legacy option handling capability that may disappear at some point.
Sorry, I have no clue what you're saying. I'm far from an IM expert. What does "read your image" mean? Which option is deprecated, and what should I use instead?
Thanks,
Tim