Package gw.util

Class ShellProcess


  • public class ShellProcess
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Process _javaProcess  
      private java.io.PrintWriter _stdin  
    • Constructor Summary

      Constructors 
      Constructor Description
      ShellProcess​(java.lang.Process javaProcess)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void closeStderr()  
      void closeStdin()  
      void closeStdout()  
      void destroy()
      Kills the subprocess.
      int exitValue()
      Returns the exit value for the subprocess.
      boolean getIsDone()
      Returns true if the process is done, false if not
      java.lang.String readChar()  
      java.lang.String readLine()
      Reads a line of text from stdout.
      java.lang.String readStderrLine()
      Reads a line of text from stderr.
      java.lang.String readStderrUntil​(char character, boolean includeDeliminator)
      Reads a group of text from stderr.
      private java.lang.String readStreamUntil​(java.io.InputStream stream, boolean includeDelim, char... character)  
      java.lang.String readUntil​(java.lang.String character, boolean includeDeliminator)
      Reads a group of text from stdout.
      int waitFor()
      Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.
      void write​(java.lang.String text)
      Writes the specified text to stdin
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _javaProcess

        private java.lang.Process _javaProcess
      • _stdin

        private java.io.PrintWriter _stdin
    • Constructor Detail

      • ShellProcess

        ShellProcess​(java.lang.Process javaProcess)
    • Method Detail

      • readLine

        public java.lang.String readLine()
        Reads a line of text from stdout. This method will block until a newline(\n) character has been received. This method is equivilent to calling readUntil('\n', false)<\i>
        Returns:
        The line of text that was read
      • readUntil

        public java.lang.String readUntil​(java.lang.String character,
                                          boolean includeDeliminator)
        Reads a group of text from stdout. The line will start from the previous point until the read character. This method will block until the specified character is read.
        Parameters:
        character - the character to read until
        includeDeliminator - true to include the deliminator in the returned text, false to not.
        Returns:
        The text that was read
      • readChar

        public java.lang.String readChar()
      • readStderrLine

        public java.lang.String readStderrLine()
        Reads a line of text from stderr. This method will block until a newline(\n) character has been received. This method is equivilent to calling readUntil('\n', false)<\i>
        Returns:
        The line of text that was read
      • readStderrUntil

        public java.lang.String readStderrUntil​(char character,
                                                boolean includeDeliminator)
        Reads a group of text from stderr. The line will start from the previous point until the read character. This method will block until the specified character is read.
        Parameters:
        character - the character to read until
        includeDeliminator - true to include the deliminator in the returned text, false to not.
        Returns:
        The text that was read
      • write

        public void write​(java.lang.String text)
        Writes the specified text to stdin
        Parameters:
        text - the text to write
      • closeStdout

        public void closeStdout()
      • closeStderr

        public void closeStderr()
      • closeStdin

        public void closeStdin()
      • waitFor

        public int waitFor()
                    throws java.lang.InterruptedException
        Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits.
        Returns:
        the exit value of the process. By convention, 0 indicates normal termination.
        Throws:
        java.lang.InterruptedException - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an InterruptedException is thrown.
      • exitValue

        public int exitValue()
        Returns the exit value for the subprocess.
        Returns:
        the exit value of the subprocess represented by this Process object. by convention, the value 0 indicates normal termination.
        Throws:
        java.lang.IllegalThreadStateException - if the subprocess represented by this Process object has not yet terminated.
      • getIsDone

        public boolean getIsDone()
        Returns true if the process is done, false if not
      • destroy

        public void destroy()
        Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.
      • readStreamUntil

        private java.lang.String readStreamUntil​(java.io.InputStream stream,
                                                 boolean includeDelim,
                                                 char... character)