我通过java的ProcessBuilder使用imagemagick的比较命令。
我想将比较的输出提供给文本文件。我的命令运行正常,但我没有在我的文本文件中获得任何输出。通过cmd运行相同的compare命令时,我将输出作为
C:\Image11.jpg JPEG 279x181 279x181+0+0 8-bit sRGB 15.8K
B 0.000u 0:00.000
C:\Image12.jpg JPEG 279x181 279x181+0+0 8-bit sRGB 15.8K
B 0.000u 0:00.000
Image: C:\Image11.jpg
Channel distortion: RMSE
red: 0 (0)
green: 0 (0)
blue: 0 (0)
all: 0 (0)
有关可能出现问题的任何建议。这是我的代码..
public class Test {
public static void colorROI(String[] command) throws IOException{
ProcessBuilder pb = new ProcessBuilder(command);
Process process = pb.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
FileHandler fh = new FileHandler("D:/log.txt");
Logger logger = Logger.getLogger("global");
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
String line = null;
while ((line = stdInput.readLine()) != null) {
logger.log(Level.INFO, line);
}
}
public static void main(String[] args) throws IOException, InterruptedException {
String[] command = {"cmd.exe","/c","cd \"C:\\Program Files\\ImageMagick-6.8.9-Q16\" && compare -verbose -metric rmse \"C:\\Image11.jpg\" \"C:\\Image12.jpg\" \"C:\\Image13.jpg\"" };
colorROI(command);
}
}
答案 0 :(得分:0)
我终于明白了。实际上在imagemagick中,命令的输出被定向到InputStream的ErrorStream instread。将其更改为errorstream解决了这个问题。
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getErrorStream()));