Class Process

java.lang.Object
com.codename1.io.Process
All Implemented Interfaces:
AutoCloseable

public abstract class Process extends Object implements AutoCloseable
A child OS process. Stream directions and lifecycle methods follow JavaSE. Read stdout and stderr concurrently to avoid filling a pipe. Never wait or do blocking stream I/O on the EDT. Interrupting a wait does not kill the child. Unlike JavaSE, this class is AutoCloseable: close forcibly terminates the direct child and closes its three streams. Descendants are not terminated.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Forcibly terminates the child and releases all pipes, even if one close fails.
    abstract void
    Requests termination of the direct child.
    abstract Process
    Forcibly terminates the direct child; completion is asynchronous.
    abstract int
    Returns the exit code, or throws IllegalThreadStateException while alive.
    abstract InputStream
    The child's stderr; EOF when redirectErrorStream(true) was selected.
    abstract InputStream
    The child's stdout (the parent reads from it).
    abstract OutputStream
    The child's stdin (the parent writes to it).
    boolean
    Whether the direct child is still running.
    protected void
    pause(long millis)
    Port hook for a bounded wait between exit polls.
    int
    Waits for exit.
    boolean
    waitFor(long timeoutMillis)
    Waits at most timeout milliseconds.
    boolean
    waitFor(long timeout, TimeUnit unit)
    JavaSE-style timed wait; sub-millisecond positive durations round up.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Process

      public Process()
  • Method Details

    • getOutputStream

      public abstract OutputStream getOutputStream()
      The child's stdin (the parent writes to it).
    • getInputStream

      public abstract InputStream getInputStream()
      The child's stdout (the parent reads from it).
    • getErrorStream

      public abstract InputStream getErrorStream()
      The child's stderr; EOF when redirectErrorStream(true) was selected.
    • exitValue

      public abstract int exitValue()
      Returns the exit code, or throws IllegalThreadStateException while alive.
    • destroy

      public abstract void destroy()
      Requests termination of the direct child. On Windows this is forcible.
    • destroyForcibly

      public abstract Process destroyForcibly()
      Forcibly terminates the direct child; completion is asynchronous.
    • isAlive

      public boolean isAlive()
      Whether the direct child is still running.
    • waitFor

      public int waitFor() throws InterruptedException
      Waits for exit. An interrupt cancels only this wait.
      Throws:
      InterruptedException
    • waitFor

      public boolean waitFor(long timeoutMillis) throws InterruptedException
      Waits at most timeout milliseconds. Zero/negative values only poll.
      Throws:
      InterruptedException
    • pause

      protected void pause(long millis) throws InterruptedException
      Port hook for a bounded wait between exit polls.
      Throws:
      InterruptedException
    • waitFor

      public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException
      JavaSE-style timed wait; sub-millisecond positive durations round up.
      Throws:
      InterruptedException
    • close

      public void close() throws IOException
      Forcibly terminates the child and releases all pipes, even if one close fails. The runtime reaps it independently; this does not wait for termination.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException