public String executionCommand(String command) throws Exception { String msg = ""; Process process try { process = Runtime.getRuntime().exec(["bash", "-c",command] as String[]); InputStream is1 = process.getInputStream(); InputStream is2 = process.getErrorStream(); new Thread(){ public void run(){ BufferedReader br1 = new BufferedReader(new InputStreamReader(is1)); try{ String line1 = null; while ((line1 = br1.readLine()) != null){ if(line1 != null){} } }catch (IOException e){ e.printStackTrace(); } finally { try { is1.close(); }catch (IOException e){ e.printStackTrace(); } } } }.start(); new Thread(){ public void run(){ BufferedReader br2 = new BufferedReader(new InputStreamReader(is2)); try{ String line2 = null; while ((line2 = br2.readLine()) != null){ if(line2 != null){} } }catch (IOException e){ e.printStackTrace(); } finally { try { is2.close(); }catch (IOException e){ e.printStackTrace(); } } } }.start(); process.waitFor(); process.destroy(); msg = "success"; }catch (Exception e){ msg = "failure"; try{ process.getErrorStream().close(); process.getInputStream().close(); process.getOutputStream().close(); }catch (Exception ee){ ee.printStackTrace(); } } return msg; }
java 实现mysql数据库备份,以及 Runtime.getRuntime().exec 阻塞解
最新推荐文章于 2023-05-30 09:28:57 发布