Record Class ProcessResult
java.lang.Object
java.lang.Record
cloud.opencode.base.core.process.ProcessResult
- Record Components:
exitCode- the process exit code (0 typically means success) - 进程退出码(0 通常表示成功)stdout- captured standard output - 捕获的标准输出stderr- captured standard error - 捕获的标准错误duration- wall-clock execution time - 挂钟执行时间command- the command that was executed - 执行的命令
public record ProcessResult(int exitCode, String stdout, String stderr, Duration duration, List<String> command)
extends Record
ProcessResult - Immutable result of a process execution
ProcessResult - 进程执行的不可变结果
Captures the exit code, standard output, standard error, wall-clock duration, and the command that was executed.
捕获退出码、标准输出、标准错误、挂钟时间以及执行的命令。
Usage Examples | 使用示例:
ProcessResult result = ProcessManager.execute("ls", "-la");
if (result.isSuccess()) {
System.out.println(result.stdout());
}
// Or throw on failure
ProcessManager.execute("git", "status").orThrow();
Thread Safety | 线程安全: This record is immutable and thread-safe. 此记录是不可变的,线程安全。
- Since:
- JDK 25, opencode-base-core V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncommand()Returns the value of thecommandrecord component.duration()Returns the value of thedurationrecord component.final booleanIndicates whether some other object is "equal to" this one.intexitCode()Returns the value of theexitCoderecord component.final inthashCode()Returns a hash code value for this object.booleanReturnstrueif the process exited with code 0.static ProcessResultCreates a newProcessResult.orThrow()Returns this result if successful, otherwise throws anOpenException.output()Alias forstdout().stderr()Returns the value of thestderrrecord component.stdout()Returns the value of thestdoutrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ProcessResult
-
-
Method Details
-
of
public static ProcessResult of(int exitCode, String stdout, String stderr, Duration duration, List<String> command) Creates a newProcessResult. 创建新的ProcessResult。- Parameters:
exitCode- the exit code - 退出码stdout- standard output - 标准输出stderr- standard error - 标准错误duration- execution duration - 执行时间command- the command - 命令- Returns:
- a new ProcessResult - 新的 ProcessResult
-
isSuccess
public boolean isSuccess()Returnstrueif the process exited with code 0. 如果进程以退出码 0 退出,返回true。- Returns:
- true if exit code is 0 - 退出码为 0 时返回 true
-
output
-
orThrow
Returns this result if successful, otherwise throws anOpenException. 如果成功则返回此结果,否则抛出OpenException。The exception message includes the exit code, command, and a truncated stderr snippet. Callers should be cautious about exposing this exception to end users, as stderr may contain sensitive system information.
异常消息包含退出码、命令和截断的 stderr 片段。 调用者应注意不要将此异常暴露给最终用户,因为 stderr 可能包含敏感系统信息。
- Returns:
- this result if exit code is 0 - 退出码为 0 时返回此结果
- Throws:
OpenException- if exit code is not 0 - 退出码不为 0 时抛出
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
exitCode
-
stdout
-
stderr
-
duration
-
command
-