Class ProcessHandle

java.lang.Object
org.opentestfactory.utils.process.ProcessHandle

public class ProcessHandle extends Object
This class is a process handle. It allows process streams monitoring and process termination management.
Author:
edegenetais
  • Constructor Details

    • ProcessHandle

      public ProcessHandle(Process process)
      Create a process handle without shutdown hook.
      Parameters:
      process - process to manage.
    • ProcessHandle

      public ProcessHandle(String processName, Process process, boolean registerShutdownHook, boolean monitorErrorStream)
      Create a process handle.
      Parameters:
      processName - name for the process
      process - process to manage.
      registerShutdownHook - whether to register a process shutdown hook or not.
      monitorErrorStream - if the error stream should be monitored.
    • ProcessHandle

      public ProcessHandle(String processName, Process process, boolean registerShutdownHook, boolean monitorErrorStream, int maxLength)
      Create a process handle.
      Parameters:
      processName - name for the process
      process - process to manage.
      registerShutdownHook - whether to register a process shutdown hook or not.
      monitorErrorStream - if the error stream should be monitored.
      maxLength - max stderr record length to keep
    • ProcessHandle

      public ProcessHandle(String processName, Process process, boolean registerShutdownHook, boolean monitorStdoutStream, boolean monitorErrorStream, int maxLength)
  • Method Details

    • killProcess

      public void killProcess()
      Kill the underlying process.
    • isProcessAlive

      public boolean isProcessAlive()
      Check if the underlying process is still alive.
      Returns:
      true if alive, false if dead.
    • returnValue

      public Integer returnValue()
      Returns:
      process's return value.
    • getErrorStream

      public String getErrorStream()
      Get the last 200 lines of the process error stream.
      Returns:
    • getStdoutStream

      public String getStdoutStream()
      Get the last 200 lines of the process error stream.
      Returns:
    • getProcessName

      public String getProcessName()