Class RuntimeUtil

java.lang.Object
com.sure.tool.util.RuntimeUtil

public class RuntimeUtil extends Object
运行时命令执行工具类,参考 Hutool 的 RuntimeUtil 设计。

English: Process execution helpers that capture output as a string or lines.

Since:
0.1.0
Author:
suretool
  • Method Details

    • exec

      public static Process exec(String... command) throws IOException
      执行命令,返回进程对象(标准输出与错误输出合并)。
      Parameters:
      command - 命令及参数
      Returns:
      进程对象
      Throws:
      IOException - IO 异常
    • execForStr

      public static String execForStr(String... command) throws IOException
      执行命令并读取全部标准输出为字符串(UTF-8,去除末尾换行)。
      Parameters:
      command - 命令及参数
      Returns:
      标准输出
      Throws:
      IOException - IO 异常
    • execForStr

      public static String execForStr(Charset charset, String... command) throws IOException
      执行命令并读取全部标准输出为字符串(去除末尾换行)。
      Parameters:
      charset - 字符集
      command - 命令及参数
      Returns:
      标准输出
      Throws:
      IOException - IO 异常
    • execForLines

      public static List<String> execForLines(String... command) throws IOException
      执行命令并读取全部标准输出为行列表。
      Parameters:
      command - 命令及参数
      Returns:
      行列表
      Throws:
      IOException - IO 异常