Java calling code:
try { String shpath = "/tmp/topdf.sh";//Script path, the source doc path needs to be configured as a variable in the script, which is entered as a parameter when called by the downlink program String cmd = "param";//xshell script input parameters Process ps = Runtime.getRuntime().exec(shpath,cmd);// ps.waitFor();//Wait for the conversion result BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } String result = sb.toString(); System.out.println(result); } catch (Exception e) { e.printStackTrace (); }
#!/bin/sh source=$1 echo ${source} soffice --headless --invisible --convert-to pdf ${source} --outdir /tmp/
But found that the command no longer responds after running for a period of time, and there is no document result. After checking the server, libreoffice is running fine, but the soffice --convert-to command is unresponsive and no output. View active threads as follows:
There are two related active instances running.
After reading the information, this is a bug generated by LO in 2011, related bug list reference:
https://bugs.documentfoundation.org/show_bug.cgi?id=37531
https://bugs.documentfoundation.org/show_bug.cgi?id=45026
大体意思是LO GUI实例一旦运行过一个,再运行一个实例的话,就会出现无响应的问题。解决思路有两个:
1、杀掉所有的libreoffice实例,即将上面的两个实例杀掉
2、执行命令时增加一行参数,经测试下面两条命令均可以执行【必须保证命令的执行要有权限】:
soffice --headless --convert-to pdf ${source-file} --outdir ${target-path} "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"
soffice --headless --convert-to pdf ${source-file} --outdir ${target-path} -env:UserInstallation=file:///home/user/.libreoffice-alt
程序员,除了编码,生活还应该有沉淀!