Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

imagemagick - execute an external command in java

Is there a way to execute a command in java that doesn't suffer from the startup overhead (slowness) of using ProcessBuilder?

More detail: I am using im4java which is a java library that internally uses ProcessBuilder to execute imagemagick's programs. It is slow. I have created a small unit test that shows that ProcessBuilder (not im4java) is the problem. The slowness is the startup overhead of using ProcessBuilder. I have found posts around the internet saying processbuider has overhead so its not just me saying it does.

List<String> commands = new ArrayList<String>();
commands.add("C:\PROGRA~2\ImageMagick-6.6.4-Q16\convert.exe");
commands.add("dog.jpg");
commands.add("output.jpg");
ProcessBuilder processBuilder = new ProcessBuilder(commands);
Process start = processBuilder.start();
start.waitFor();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Runtime.getRuntime().exec(...)  

can be used to run an external command. You can turn your List into a command array or a string to pass to exec().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...