diff --git a/src/com/platform/utils/ProcessMyUtil.java b/src/com/platform/utils/ProcessMyUtil.java index 74628834..725aa315 100644 --- a/src/com/platform/utils/ProcessMyUtil.java +++ b/src/com/platform/utils/ProcessMyUtil.java @@ -14,48 +14,30 @@ public class ProcessMyUtil { public List execCmdWaitAcquiescent(String cmd) { -// String host=Constant.hostIp; -// String username=Constant.rootUser; -// String password=Constant.rootPasswd; -// int port=Constant.port; - List reStrings = new ArrayList(); - + return runcmd(cmd); + } + + private List runcmd(String cmd) { + List result = new ArrayList(); + InputStream in = null; + String[] cmds = {"/bin/sh", "-c", cmd}; try { - ProcessBuilder pb = null; - Process pro = null; - - if (cmd.contains("grep")) { - List cmds = new ArrayList(); - cmds.add("sh"); - cmds.add("-c"); - cmds.add(cmd); - new ProcessBuilder(cmds); - pro = pb.start(); - - }else { - pro = Runtime.getRuntime().exec(cmd); - } - if (null == pro) { - return reStrings; - } - BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream())); - StringBuffer sb = new StringBuffer(); - String line; - while ((line = br.readLine()) != null) { - if (line != null) { -// System.out.println(line); - reStrings.add(line); - } else { - break; - } - } - if(reStrings.size()==0){ + Process pro = Runtime.getRuntime().exec(cmds); + pro.waitFor(); + in = pro.getInputStream(); + BufferedReader read = new BufferedReader(new InputStreamReader(in)); + String line = null; + while ((line=read.readLine()) != null) { + result.add(line); } } catch (IOException e) { - // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InterruptedException e) { e.printStackTrace(); } - return reStrings; +// String[] strs = new String[result.size()]; +// return result.toArray(strs); + return result; } }