Skip to main content
add suggestion to run convert on its own without any arguments
Source Link
Luke Woodward
  • 65.3k
  • 16
  • 94
  • 108

EDIT: if things still aren't working, then the next step is to see whether the problem is that convert isn't being found. Let's just run convert on its own without any arguments and see if it spits out its usage message to standard output. Run the following:

public class test1 {
    public static void main(String argv[]) throws IOException, InterruptedException {

        ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "convert");
        pb.redirectErrorStream(true);
        Process p = pb.start();
        StreamGobbler g = new StreamGobbler(p.getInputStream(), "OUT");
        g.start();
        p.waitFor();
    }
}

Use the StreamGobbler class here. Does this print out convert's usage method, with each line prefixed with OUT>?

EDIT: if things still aren't working, then the next step is to see whether the problem is that convert isn't being found. Let's just run convert on its own without any arguments and see if it spits out its usage message to standard output. Run the following:

public class test1 {
    public static void main(String argv[]) throws IOException, InterruptedException {

        ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "convert");
        pb.redirectErrorStream(true);
        Process p = pb.start();
        StreamGobbler g = new StreamGobbler(p.getInputStream(), "OUT");
        g.start();
        p.waitFor();
    }
}

Use the StreamGobbler class here. Does this print out convert's usage method, with each line prefixed with OUT>?

redirect stderr into stdout (shame on me for missing this first time...), wrap directory in java.io.File
Source Link
Luke Woodward
  • 65.3k
  • 16
  • 94
  • 108

A couple of things to try (both of which are untested):

  1. Put a cd in the command line and use && to run both commands in one line.

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;
    
     import org.omg.CORBA.portable.OutputStream;
    
      public class test1 {
         public static void main(String argv[]) throws IOException, InterruptedException {
    
             ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "cd C:\\Users\\Robert\\Java-workspace\\Crop_test\\Crop_test1\\ && convert -crop 312x312+0-10 image1.jpg new_image1.jpg"); 
             pb.redirectErrorStream(true);
             Process p = pb.start();
             p.waitFor();
         }
     }
    
  2. Change the directory that the ProcessBuilder starts in:

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;
    
     import org.omg.CORBA.portable.OutputStream;
    
      public class test1 {
         public static void main(String argv[]) throws IOException, InterruptedException {
    
             ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "convert -crop 312x312+0-10 image1.jpg new_image1.jpg");
             pb.directory(new File("C:\\Users\\Robert\\Java-workspace\\Crop_test\\Crop_test1\\"));
             pb.redirectErrorStream(true);
             Process p = pb.start();
             p.waitFor();
         }
     }
    

Incidentally, are you sure you want to import org.omg.CORBA.portable.OutputStream? Did you mean java.io.OutputStream instead?

A couple of things to try (both of which are untested):

  1. Put a cd in the command line and use && to run both commands in one line.

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;
    
     import org.omg.CORBA.portable.OutputStream;
    
      public class test1 {
         public static void main(String argv[]) throws IOException, InterruptedException {
    
             ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "cd C:\\Users\\Robert\\Java-workspace\\Crop_test\\Crop_test1\\ && convert -crop 312x312+0-10 image1.jpg new_image1.jpg"); 
             Process p = pb.start();
             p.waitFor();
         }
     }
    
  2. Change the directory that the ProcessBuilder starts in:

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;
    
     import org.omg.CORBA.portable.OutputStream;
    
      public class test1 {
         public static void main(String argv[]) throws IOException, InterruptedException {
    
             ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "convert -crop 312x312+0-10 image1.jpg new_image1.jpg");
             pb.directory("C:\\Users\\Robert\\Java-workspace\\Crop_test\\Crop_test1\\");
             Process p = pb.start();
             p.waitFor();
         }
     }
    

Incidentally, are you sure you want to import org.omg.CORBA.portable.OutputStream? Did you mean java.io.OutputStream instead?

A couple of things to try (both of which are untested):

  1. Put a cd in the command line and use && to run both commands in one line.

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;
    
     import org.omg.CORBA.portable.OutputStream;
    
      public class test1 {
         public static void main(String argv[]) throws IOException, InterruptedException {
    
             ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "cd C:\\Users\\Robert\\Java-workspace\\Crop_test\\Crop_test1\\ && convert -crop 312x312+0-10 image1.jpg new_image1.jpg"); 
             pb.redirectErrorStream(true);
             Process p = pb.start();
             p.waitFor();
         }
     }
    
  2. Change the directory that the ProcessBuilder starts in:

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;
    
     import org.omg.CORBA.portable.OutputStream;
    
      public class test1 {
         public static void main(String argv[]) throws IOException, InterruptedException {
    
             ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "convert -crop 312x312+0-10 image1.jpg new_image1.jpg");
             pb.directory(new File("C:\\Users\\Robert\\Java-workspace\\Crop_test\\Crop_test1\\"));
             pb.redirectErrorStream(true);
             Process p = pb.start();
             p.waitFor();
         }
     }
    

Incidentally, are you sure you want to import org.omg.CORBA.portable.OutputStream? Did you mean java.io.OutputStream instead?

Source Link
Luke Woodward
  • 65.3k
  • 16
  • 94
  • 108

A couple of things to try (both of which are untested):

  1. Put a cd in the command line and use && to run both commands in one line.

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;
    
     import org.omg.CORBA.portable.OutputStream;
    
      public class test1 {
         public static void main(String argv[]) throws IOException, InterruptedException {
    
             ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "cd C:\\Users\\Robert\\Java-workspace\\Crop_test\\Crop_test1\\ && convert -crop 312x312+0-10 image1.jpg new_image1.jpg"); 
             Process p = pb.start();
             p.waitFor();
         }
     }
    
  2. Change the directory that the ProcessBuilder starts in:

     import java.io.BufferedReader;
     import java.io.IOException;
     import java.io.InputStreamReader;
    
     import org.omg.CORBA.portable.OutputStream;
    
      public class test1 {
         public static void main(String argv[]) throws IOException, InterruptedException {
    
             ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "convert -crop 312x312+0-10 image1.jpg new_image1.jpg");
             pb.directory("C:\\Users\\Robert\\Java-workspace\\Crop_test\\Crop_test1\\");
             Process p = pb.start();
             p.waitFor();
         }
     }
    

Incidentally, are you sure you want to import org.omg.CORBA.portable.OutputStream? Did you mean java.io.OutputStream instead?