Class ProcessConfig

java.lang.Object
cloud.opencode.base.core.process.ProcessConfig

public final class ProcessConfig extends Object
ProcessConfig - Configuration for process execution ProcessConfig - 进程执行配置

Immutable configuration object built via the ProcessConfig.Builder pattern. Controls command, working directory, environment variables, timeout, stream redirection, and IO inheritance.

通过 ProcessConfig.Builder 模式构建的不可变配置对象。 控制命令、工作目录、环境变量、超时时间、流重定向和 IO 继承。

Usage Examples | 使用示例:

ProcessConfig config = ProcessConfig.builder("ls", "-la")
        .workingDirectory(Path.of("/tmp"))
        .environment("LANG", "en_US.UTF-8")
        .timeout(Duration.ofSeconds(30))
        .build();

ProcessResult result = ProcessManager.execute(config);

Thread Safety | 线程安全: Instances are immutable and thread-safe. 实例是不可变的,线程安全。

Since:
JDK 25, opencode-base-core V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • builder

      public static ProcessConfig.Builder builder(String... command)
      Creates a new builder with the given command. 以给定命令创建新的构建器。
      Parameters:
      command - the command and arguments - 命令和参数
      Returns:
      a new builder - 新的构建器
      Throws:
      IllegalArgumentException - if command is empty - 若命令为空
    • builder

      public static ProcessConfig.Builder builder(List<String> command)
      Creates a new builder with the given command list. 以给定命令列表创建新的构建器。
      Parameters:
      command - the command and arguments - 命令和参数
      Returns:
      a new builder - 新的构建器
      Throws:
      IllegalArgumentException - if command is empty - 若命令为空
    • command

      public List<String> command()
      Returns the command and arguments. 返回命令和参数。
      Returns:
      unmodifiable command list - 不可修改的命令列表
    • workingDirectory

      public Path workingDirectory()
      Returns the working directory, or null to inherit from the parent process. 返回工作目录,若为 null 则继承父进程。
      Returns:
      the working directory, or null - 工作目录,或 null
    • environment

      public Map<String,String> environment()
      Returns additional environment variables. 返回附加环境变量。
      Returns:
      unmodifiable environment map - 不可修改的环境变量映射
    • timeout

      public Duration timeout()
      Returns the execution timeout, or null for no timeout. 返回执行超时时间,若为 null 则无超时。
      Returns:
      the timeout, or null - 超时时间,或 null
    • redirectErrorStream

      public boolean redirectErrorStream()
      Returns whether stderr should be merged into stdout. 返回是否将 stderr 合并到 stdout。
      Returns:
      true if error stream is redirected - 若错误流被重定向则为 true
    • stdoutFile

      public Path stdoutFile()
      Returns the file to redirect stdout to, or null for in-memory capture. 返回 stdout 重定向的文件,若为 null 则在内存中捕获。
      Returns:
      stdout file, or null - stdout 文件,或 null
    • stderrFile

      public Path stderrFile()
      Returns the file to redirect stderr to, or null for in-memory capture. 返回 stderr 重定向的文件,若为 null 则在内存中捕获。
      Returns:
      stderr file, or null - stderr 文件,或 null
    • inheritIO

      public boolean inheritIO()
      Returns whether the process should inherit the parent's IO. 返回进程是否继承父进程的 IO。
      Returns:
      true if inheriting IO - 若继承 IO 则为 true
    • toString

      public String toString()
      Overrides:
      toString in class Object