I need to call an external program from Java such as ImageMagick's convert
. It fails to work on Windows unless I put cmd /c
before the actual command.
String source = "test.jpg";
String result = "test-thumbnail.jpg";
ProcessBuilder builder = new ProcessBuilder().command("cmd", "/c", "convert", source, "-thumbnail", "295x", result);
Process process = builder.start();
How to avoid using cmd /c
so that my code works on OS other than Windows?
Without cmd /c
I get into very similar problem as described here: running imagemagick convert (console application) from python - that there exists a native Windows convert.exe
which is being called rather than ImageMagick's convert.exe
. It seems like PATH
is not picked by environment of the child process.
I have double checked that my system PATH
has ImageMagick directory before C:\Windows\system32
. Also the command itself runs perfectly fine when I type it into the Windows command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With