Package io.karatelabs.process
Class ProcessHandle
java.lang.Object
io.karatelabs.process.ProcessHandle
- All Implemented Interfaces:
io.karatelabs.js.ObjectLike,io.karatelabs.js.SimpleObject
Main process wrapper exposed to JavaScript.
Manages process lifecycle, stream readers, and line dispatch.
Supports two creation modes: 1. Immediate start: ProcessHandle.start(config) - starts process immediately 2. Deferred start: ProcessHandle.create(config) then handle.start() - allows setup before start
-
Field Summary
Fields inherited from interface io.karatelabs.js.SimpleObject
TO_STRING -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidclose(boolean force) static ProcessHandlecreate(ProcessConfig config) Create ProcessHandle without starting the process.intlonggetPid()booleanisAlive()jsKeys()Add a stderr listener.Add a stdout listener.voidsetSignalConsumer(Consumer<Object> consumer) voidstart()Start the process.static ProcessHandlestart(ProcessConfig config) Create and immediately start ProcessHandle.booleanwaitForHttp(String url, int attempts, int intervalMs) waitForOutput(Predicate<String> predicate) Wait until predicate returns true for an output line.waitForOutput(Predicate<String> predicate, long timeoutMillis) Wait until predicate returns true for an output line, with timeout.booleanwaitForPort(String host, int port, int attempts, int intervalMs) intwaitSync()intwaitSync(long timeoutMillis) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.karatelabs.js.ObjectLike
getMember, getPrototype, isExtensible, isFrozen, isOwnProperty, isSealed, putMember, removeMember, setExtensible, setFrozen, setSealedMethods inherited from interface io.karatelabs.js.SimpleObject
getMember, jsToString, putMember, removeMember, toMap
-
Method Details
-
create
Create ProcessHandle without starting the process. Call start() to begin execution. -
start
Create and immediately start ProcessHandle. -
start
Start the process. Can only be called once. -
onStdOut
Add a stdout listener. Can be called before or after start(). When redirectErrorStream is true (default), receives both stdout and stderr. -
onStdErr
Add a stderr listener. Can be called before or after start(). Only receives lines when redirectErrorStream is false. -
waitSync
public int waitSync() -
waitSync
public int waitSync(long timeoutMillis) -
waitForOutput
Wait until predicate returns true for an output line.- Parameters:
predicate- Test function that receives the line- Returns:
- The line that matched
-
waitForOutput
Wait until predicate returns true for an output line, with timeout.- Parameters:
predicate- Test function that receives the linetimeoutMillis- Timeout in milliseconds (0 = no timeout)- Returns:
- The line that matched
-
getStdOut
-
getStdErr
-
getExitCode
public int getExitCode() -
isAlive
public boolean isAlive() -
close
public void close() -
close
public void close(boolean force) -
getPid
public long getPid() -
getExitFuture
-
setSignalConsumer
-
signal
-
waitForPort
-
waitForHttp
-
jsKeys
- Specified by:
jsKeysin interfaceio.karatelabs.js.SimpleObject
-
jsGet
- Specified by:
jsGetin interfaceio.karatelabs.js.SimpleObject
-