Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 579 Bytes

脚本调用.md

File metadata and controls

22 lines (19 loc) · 579 Bytes

调用服务器本地脚本

代码

  public static String exec(String command) {
    StringBuilder sb = new StringBuilder();
    try {
      Process exec = Runtime.getRuntime().exec(command);
      exec.waitFor();
      BufferedReader br = new BufferedReader(new InputStreamReader(exec.getInputStream()));
      String tmp = null;
      while ((tmp = br.readLine()) != null) {
        sb.append(tmp);
      }
    } catch (IOException | InterruptedException e) {
      throw new RuntimeException(e);
    }
    return sb.toString();
  }