Class ProcessConfig.Builder
java.lang.Object
cloud.opencode.base.core.process.ProcessConfig.Builder
- Enclosing class:
ProcessConfig
Builder for
ProcessConfig.
ProcessConfig 的构建器。- Since:
- JDK 25, opencode-base-core V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds theProcessConfig.Sets the command and arguments.Sets the command and arguments.environment(String key, String value) Adds a single environment variable.environment(Map<String, String> env) Adds multiple environment variables.inheritIO(boolean inherit) Sets whether the process should inherit the parent's IO streams.redirectErrorStream(boolean redirect) Sets whether stderr should be merged into stdout.stderrFile(Path file) Redirects stderr to a file.stdoutFile(Path file) Redirects stdout to a file.Sets the execution timeout.Sets the execution timeout.workingDirectory(Path dir) Sets the working directory for the process.
-
Method Details
-
command
Sets the command and arguments. 设置命令和参数。- Parameters:
command- the command and arguments - 命令和参数- Returns:
- this builder - 此构建器
-
command
Sets the command and arguments. 设置命令和参数。- Parameters:
command- the command list - 命令列表- Returns:
- this builder - 此构建器
-
workingDirectory
Sets the working directory for the process. 设置进程的工作目录。- Parameters:
dir- the working directory, or null to inherit - 工作目录,或 null 以继承- Returns:
- this builder - 此构建器
-
environment
Adds a single environment variable. 添加单个环境变量。Security Warning | 安全警告: Do not pass untrusted input as environment variable names or values. Dangerous variables like
LD_PRELOAD,PATH, orDYLD_INSERT_LIBRARIEScan lead to code execution.安全警告: 切勿将不可信输入作为环境变量名或值传入。
LD_PRELOAD、PATH等危险变量可导致代码执行。- Parameters:
key- the variable name - 变量名value- the variable value - 变量值- Returns:
- this builder - 此构建器
-
environment
Adds multiple environment variables. 添加多个环境变量。- Parameters:
env- the environment variables - 环境变量- Returns:
- this builder - 此构建器
-
timeout
Sets the execution timeout. 设置执行超时时间。- Parameters:
timeout- the timeout duration, or null for no timeout - 超时时间,或 null 表示无超时- Returns:
- this builder - 此构建器
-
timeout
Sets the execution timeout. 设置执行超时时间。- Parameters:
amount- the timeout amount - 超时数量unit- the time unit - 时间单位- Returns:
- this builder - 此构建器
-
redirectErrorStream
Sets whether stderr should be merged into stdout. 设置是否将 stderr 合并到 stdout。- Parameters:
redirect- true to merge stderr into stdout - 若为 true 则合并 stderr 到 stdout- Returns:
- this builder - 此构建器
-
stdoutFile
Redirects stdout to a file. 将 stdout 重定向到文件。- Parameters:
file- the target file, or null for in-memory capture - 目标文件,或 null 以在内存中捕获- Returns:
- this builder - 此构建器
-
stderrFile
Redirects stderr to a file. 将 stderr 重定向到文件。- Parameters:
file- the target file, or null for in-memory capture - 目标文件,或 null 以在内存中捕获- Returns:
- this builder - 此构建器
-
inheritIO
Sets whether the process should inherit the parent's IO streams. 设置进程是否继承父进程的 IO 流。When enabled, stdout/stderr will not be captured in memory.
启用后,stdout/stderr 将不会在内存中捕获。
- Parameters:
inherit- true to inherit IO - 若为 true 则继承 IO- Returns:
- this builder - 此构建器
-
build
Builds theProcessConfig. 构建ProcessConfig。- Returns:
- a new immutable ProcessConfig - 新的不可变 ProcessConfig
- Throws:
IllegalArgumentException- if command is empty - 若命令为空
-