Class ProcessHandle

java.lang.Object
io.karatelabs.process.ProcessHandle
All Implemented Interfaces:
io.karatelabs.js.ObjectLike, io.karatelabs.js.SimpleObject

public class ProcessHandle extends Object implements 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

  • Method Details

    • create

      public static ProcessHandle create(ProcessConfig config)
      Create ProcessHandle without starting the process. Call start() to begin execution.
    • start

      public static ProcessHandle start(ProcessConfig config)
      Create and immediately start ProcessHandle.
    • start

      public ProcessHandle start()
      Start the process. Can only be called once.
    • onStdOut

      public ProcessHandle onStdOut(Consumer<String> listener)
      Add a stdout listener. Can be called before or after start(). When redirectErrorStream is true (default), receives both stdout and stderr.
    • onStdErr

      public ProcessHandle onStdErr(Consumer<String> listener)
      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

      public String waitForOutput(Predicate<String> predicate)
      Wait until predicate returns true for an output line.
      Parameters:
      predicate - Test function that receives the line
      Returns:
      The line that matched
    • waitForOutput

      public String waitForOutput(Predicate<String> predicate, long timeoutMillis)
      Wait until predicate returns true for an output line, with timeout.
      Parameters:
      predicate - Test function that receives the line
      timeoutMillis - Timeout in milliseconds (0 = no timeout)
      Returns:
      The line that matched
    • getStdOut

      public String getStdOut()
    • getStdErr

      public String getStdErr()
    • getExitCode

      public int getExitCode()
    • isAlive

      public boolean isAlive()
    • close

      public void close()
    • close

      public void close(boolean force)
    • getPid

      public long getPid()
    • getExitFuture

      public CompletableFuture<Integer> getExitFuture()
    • setSignalConsumer

      public void setSignalConsumer(Consumer<Object> consumer)
    • signal

      public void signal(Object result)
    • waitForPort

      public boolean waitForPort(String host, int port, int attempts, int intervalMs)
    • waitForHttp

      public boolean waitForHttp(String url, int attempts, int intervalMs)
    • jsKeys

      public Collection<String> jsKeys()
      Specified by:
      jsKeys in interface io.karatelabs.js.SimpleObject
    • jsGet

      public Object jsGet(String key)
      Specified by:
      jsGet in interface io.karatelabs.js.SimpleObject