문제

I am writing a java aplication that edits images using imagemagick commands; However, the comands do not work and I am getting no output from them; Actually, the comand identify is not recognized and I get CreateProcess error=2; This seems odd, because the imagemagick instalation folder is included in my Path variable.

Here's my code:

     public class Test {
    public static void main(String argv[]) {
        Runtime ru = Runtime.getRuntime();

        Process p = null;
        try {
            //I've added this as a bouns, this should not be neccessary(methinks)
            String[] s = {"C:\\Program Files\\ImageMagick-6.8.6-Q16"};
            String[] cmd = {"convert", "acc-logo.jpg","-flip", "edited.jpg"};
            p = ru.exec(cmd,s);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        BufferedReader ina = new BufferedReader(new InputStreamReader(
                p.getInputStream()));
        String line = null;
        try {
            while ((line = ina.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
도움이 되었습니까?

해결책

You have a space in the path to the executable, and the Runtime.exec() call is having problems with it. Use ProcessBuilder instead; it handles spaces in arguments much more easily.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top