2014-01-05 2 views
1

프로세스 빌더를 사용하여 Windows에서 ImageMagick 명령을 실행하고 있습니다. 어떤 이유로 프로세스 빌더에서 출력 이미지가 대부분 생성되지 않습니다. Runtime.getRuntime().exec을 사용하여 동일한 명령을 시도하면 출력이 생성되었습니다. 왜 그런지 알기나 해?프로세스 빌더가 Windows에서 작동하지 않습니다.

String input="D:\\Koala.jpg"; 
String output = "D:\\ProcessBuilderOutput\\KoalaPNG.png"; 
commands.add("D:\\Program Files\\ImageMagick-6.8.6-Q16\\convert"); 
commands.add("-alpha off"); 
commands.add("-strip"); 
commands.add(input); 
commands.add("-colorspace CMYK"); 
commands.add(output); 
try{ 
    executeProcessCommand(commands); 
    if(new File(output).exists() != true){ 
    System.out.println("output not generated"); 
    } 
}catch (Exception e) { 
    e.printStackTrace(); 
} 
public static void executeProcessCommand(List<String> commands) throws Exception { 
    Process proc = null; 
    try { 
     System.out.println("-executeProcessCommand: Trying to execute :- "+commands); 
     ProcessBuilder processBuilder = new ProcessBuilder(commands); 
     proc = processBuilder.start(); 
     proc.waitFor(); 
     System.out.println("- executeProcessCommand: Executed the command "); 
    } catch (Exception e) { 
     System.out.println(" - executeProcessCommand:" + e.getMessage()); 
    } finally { 
     try { 
      if(proc != null) 
       proc.destroy(); 
     } catch (Exception e) { 
      System.out.println("executeProcessCommand:"+ e.getMessage()); 
     } 
    } 
} 
+0

commands.add("-colorspace CMYK");에 대한 지속적 또는 전혀 작동하지? 입력 파일은 무엇입니까? "작동하지 않는"것은 정확히 무엇을 의미합니까? – chrylis

+0

@ chrylis, 내가 10 번 시도했을 때 출력은 한 번만 생성되었습니다 ... 어쨌든 나는 질문을 편집했습니다 ... –

+0

[모든 Runtime.exec() (http://www.javaworld.com/jw-12-2000/jw-1229-traps.html). 그게 문제를 해결할 수도 있습니다. 그렇지 않은 경우 실패한 이유에 대한 자세한 정보를 제공해야합니다. 그런 다음'exec'을 참조하고 (계속)'ProcessBuilder'를 사용하여'Process'를 빌드한다는 것을 무시하십시오. 또한'String arg'를'String [] args'로 분해하여 그들 자신이 공백을 포함하는 인수를 설명하십시오. –

답변

1

인수를 ProcessBuilder로 분할합니다. 특히

commands.add("-alpha"); 
commands.add("off"); 

commands.add("-alpha off"); 분할 유사

+0

시도했지만 작동하지 않습니다. –