java 调用 linux shell 脚本,并读取返回值

来源:互联网 发布:淘宝p图炒作教程 编辑:程序博客网 时间:2024/06/06 09:20
String[] cmd = {"/bin/sh", "-c", "ps -elf | grep -v grep | grep EuropeStaticsEntrance | wc -l"};while (true) {    StringBuilder sb = new StringBuilder();    Process process1 = null;    process1 = Runtime.getRuntime().exec(cmd);    BufferedReader input = new BufferedReader(new InputStreamReader(process1.getInputStream()));    String line = "";    while ((line = input.readLine()) != null) {        sb.append(line);    }    input.close();    LOG.info(sb.toString().trim());    if ("0".equals(sb.toString().trim())) {        LOG.info("0".equals(sb.toString().trim()));        break;    }    LOG.info("5分钟后后再次检测");    Thread.sleep(300000);}
原创粉丝点击