java.io.IOException: Cannot run program "...": java.io.IOException: error=2, No such file or directory
The ProcessBuilder
constructors require each argument of the external program to be separate
(in the form of an array or List
of String
s). The first exception message you got,
Cannot run program "/usr/bin/libreoffice --headless --convert-to pdf:'writer_pdf_Export' --outdir /home/develop/tomcat/mf/ROOT/private/docs/0 /home/develop/tomcat/mf/ROOT/private/docs/0/35_invoice.fodt"
is not complaining that it can find a program named /usr/bin/libreoffice
. It is complaining that it can not find a program with the very long and peculiar name "/usr/bin/libreoffice --headless --convert-to pdf:'writer_pdf_Export' --outdir /home/develop/tomcat/mf/ROOT/private/docs/0 /home/develop/tomcat/mf/ROOT/private/docs/0/35_invoice.fodt
", because you concatenated the arguments into one String
.
Instead of
command.add("--convert-to pdf:'writer_pdf_Export' --outdir " + getDestinationDirectory(order) + " " + getInvoiceFilename() + ".fodt")
and such like, split each of the arguments into its own call to List.add
command.add("--convert-to");
command.add("pdf:writer_pdf_Export");
command.add("--outdir");
command.add(getDestinationDirectory(order).toString());
command.add(getInvoiceFilename() + ".fodt");
Note that there are no apostrophes around "writer_pdf_Export" since those are shell meta-characters and are not required when you're constructing an array to pass to exec
without an intermediating shell.