From 75d225e77d932a27a6fc50ad41786081fcd460d0 Mon Sep 17 00:00:00 2001 From: linzhijie <19970921lzj> Date: 星期日, 25 四月 2021 15:58:49 +0800 Subject: [PATCH] 合并代码优化 --- src/main/java/com/ots/project/tool/ShellTool.java | 35 +++-------------------------------- 1 files changed, 3 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/ots/project/tool/ShellTool.java b/src/main/java/com/ots/project/tool/ShellTool.java index 715583b..de464dd 100644 --- a/src/main/java/com/ots/project/tool/ShellTool.java +++ b/src/main/java/com/ots/project/tool/ShellTool.java @@ -15,8 +15,7 @@ } else { builder.append("libreoffice6.4 --headless --convert-to "); } - - builder.append(type).append(" "); + builder.append(type).append(":impress_pdf_Export "); builder.append("--outdir " + targetPath).append(" "); builder.append(sourcePath).append(" "); @@ -27,36 +26,8 @@ } } catch (Exception e) { } - return run_cmd(builder.toString()); + return exec(builder.toString()); } - - public static String run_cmd(String strcmd) { - // - Runtime rt = Runtime.getRuntime(); //Runtime.getRuntime()杩斿洖褰撳墠搴旂敤绋嬪簭鐨凴untime瀵硅薄 - Process ps = null; //Process鍙互鎺у埗璇ュ瓙杩涚▼鐨勬墽琛屾垨鑾峰彇璇ュ瓙杩涚▼鐨勪俊鎭�� - try { - ps = rt.exec(strcmd); //璇ュ璞$殑exec()鏂规硶鎸囩ずJava铏氭嫙鏈哄垱寤轰竴涓瓙杩涚▼鎵ц鎸囧畾鐨勫彲鎵ц绋嬪簭锛屽苟杩斿洖涓庤瀛愯繘绋嬪搴旂殑Process瀵硅薄瀹炰緥銆� - ps.waitFor(); //绛夊緟瀛愯繘绋嬪畬鎴愬啀寰�涓嬫墽琛屻�� - } catch (IOException e1) { - e1.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - int i = ps.exitValue(); //鎺ユ敹鎵ц瀹屾瘯鐨勮繑鍥炲�� - if (i == 0) { - System.out.println("鎵ц瀹屾垚."); - } else { - System.out.println("鎵ц澶辫触."); - } - - ps.destroy(); //閿�姣佸瓙杩涚▼ - ps = null; - - return null; - } - private static String exec(String command) { String returnString = ""; Runtime runTime = Runtime.getRuntime(); @@ -80,6 +51,6 @@ return returnString; } public static void main(String[] args) { - System.out.println(exec("libreoffice6.4 --headless --convert-to /root/灏忕孩.docx 灏忕孩.pdf ")); + System.out.println(exec("soffice.exe --headless --invisible --convert-to D:/ots/uploadPath/upload/2021/02/28/01e01cf7e372ba8b1c5d24b8d69a46f8.docx 01e01cf7e372ba8b1c5d24b8d69a46f8.pdf ")); } } -- Gitblit v1.9.1