0
我使用macports在OS X中安裝了imagemajick。當我從命令行(bash)運行轉換命令時,我可以將我的電影轉換爲JPG格式。但是當我通過Java Process Builder運行它時,我沒有得到這樣的輸出。是什麼賦予了。以下是我用來執行命令的java代碼。在使用OS X的java中使用Imagemajick
private void run(String[] args)
{
try
{
ProcessBuilder pb = new ProcessBuilder(args);
Process p = pb.start();
p.waitFor();
InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
is = p.getErrorStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null)
{
System.err.println(line);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
中傳遞的字符串是/ usr/local/bin目錄/轉換/Users/me/Videos/Capture-20110708-220220.mpg[0] /Users/me/Videos/out0.jpg
另請參見[當'Runtime.exec()'不會](http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)。 – trashgod
另請參見[Java技巧:從'Runtime.exec()'到ProcessBuilder](http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder的.html)。 – trashgod