• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
External Command Call - More Java Than WebObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

External Command Call - More Java Than WebObjects


  • Subject: External Command Call - More Java Than WebObjects
  • From: "Jonathan Fleming" <email@hidden>
  • Date: Fri, 04 Jul 2003 01:06:49 +0100

I want to use java.lang.Runtime.exec() to run this command line code... any ideas on how to best achieve that?
This is the command I want to run


C:\>convert -size 90x90 \Site000\web\WebObjects\My.woa\Contents\WebServerResources\fullSizeImages800pix\Conservatory.jpg -resize 90x90 +profile "*" \Site000\web\WebObjects\My.woa\Contents\WebServerResources\fullSizeImages800pix\ConservatoryThumb.jpg

The command is from ImageMagick's command line utilities.
In this code example, '-size 90x90' gives a hint to the JPEG decoder that the image is going to be downscaled to 90x90, allowing it to run faster by avoiding returning full-resolution images to ImageMagick for the subsequent resizing operation. The '-resize 90x90' specifies the desired dimensions of the output image. It will be scaled so its largest dimension is 90 pixels. The '+profile "*"' removes any ICM, EXIF, IPTC, or other profiles that might be present in the input and aren't needed in the thumbnail.


this is the route I am thinking of taking, but I don't fully understand what inner classes are all about. Here's an example of how it is said I should be using Runtime.exec().

// GoodWindowsExec.java
import java.util.*;
import java.io.*;

class StreamGobbler extends Thread
{
   InputStream is;
   String type;

   StreamGobbler(InputStream is, String type)
   {
       this.is = is;
       this.type = type;
   }

   public void run()
   {
       try
       {
           InputStreamReader isr = new InputStreamReader(is);
           BufferedReader br = new BufferedReader(isr);
           String line=null;
           while ( (line = br.readLine()) != null)
               System.out.println(type + ">" + line);
           } catch (IOException ioe)
             {
               ioe.printStackTrace();
             }
   }
}

public class GoodWindowsExec
{
   public static void main(String args[])
   {
       if (args.length < 1)
       {
           System.out.println("USAGE: java GoodWindowsExec <cmd>");
           System.exit(1);
       }

       try
       {
           String osName = System.getProperty("os.name" );
           String[] cmd = new String[3];

           if( osName.equals( "Windows NT" ) )
           {
               cmd[0] = "cmd.exe" ;
               cmd[1] = "/C" ;
               cmd[2] = args[0];
           }
           else if( osName.equals( "Windows 95" ) )
           {
               cmd[0] = "command.com" ;
               cmd[1] = "/C" ;
               cmd[2] = args[0];
           }

           Runtime rt = Runtime.getRuntime();
           System.out.println("Execing " + cmd[0] + " " + cmd[1]
                              + " " + cmd[2]);
           Process proc = rt.exec(cmd);
           // any error message?
           StreamGobbler errorGobbler = new
               StreamGobbler(proc.getErrorStream(), "ERROR");

           // any output?
           StreamGobbler outputGobbler = new
               StreamGobbler(proc.getInputStream(), "OUTPUT");

           // kick them off
           errorGobbler.start();
           outputGobbler.start();

           // any error???
           int exitVal = proc.waitFor();
           System.out.println("ExitValue: " + exitVal);

       } catch (Throwable t)
         {
           t.printStackTrace();
         }
   }
}

this is taken from this article: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Can anyone help me to utilise this code and excecute the command I want for the ImageMagick app to do it's thing?

Thanks
Jonathan :^)

_________________________________________________________________
Sign-up for a FREE BT Broadband connection today! http://www.msn.co.uk/specials/btbroadband
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: WODisplayGroup.displayableObjects()?
  • Next by Date: Re: WODisplayGroup.displayableObjects()?
  • Previous by thread: Re: WODisplayGroup.displayableObjects()?
  • Next by thread: EOModeler error with MySQL
  • Index(es):
    • Date
    • Thread