I try to switch from Runtime.exec(command) to ProcessBuilder for executing ImageMagick's convert from a Java programm. The options for convert are passed-in from the user as a String, so I cannot easily separate the arguments to pass them indvidually to ProcessBuilder's constructor. The actual command that works on the (Unix) commandline is
convert -colorspace gray -enhance -density 300 in.pdf out.pdf
How can I get this could to work:
public class Demo {
public static void main(String[] args) throws IOException, InterruptedException {
String convertOptions = "-colorspace gray -enhance -density 300"; // arguments passed in at runtime
ProcessBuilder bp = new ProcessBuilder(new String []{"convert",convertOptions,"in.pdf","out.pdf"});
Process process = bp.start();
process.waitFor();
}
}
Currently, the code justs run