Class Spawn


  • public class Spawn
    extends java.lang.Object
    This class is used for talking to processes / ports. This will also interact with the process to read and write to it.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String before()
      Returns everything that has been received from the last matched expect to the current matched expect
      void expect​(java.lang.String pattern)
      Except pattern string on std out
      int expect​(java.lang.String[] patterns)
      Except pattern string on std out
      int expect​(java.lang.String[] patterns, long timeOutSeconds)
      Except pattern string on std out
      void expect​(java.lang.String pattern, int bufferSize)
      Except pattern string on std out
      void expect​(java.lang.String pattern, long timeOutSeconds)
      Except pattern string on std out
      void expect​(java.lang.String pattern, long timeOutSeconds, int bufferSize)
      Except pattern string on std out
      void expectClose​(long timeOutSeconds)  
      void expectClose​(ExpectedOutputHandler stdOutHandler, ExpectedOutputHandler stdErrHandler)
      Wait the default timeout for the spawned process to finish.
      void expectClose​(ExpectedOutputHandler stdOutHandler, ExpectedOutputHandler stdErrHandler, long lTimeOutSeconds)
      Wait for the spawned process to finish.
      java.lang.String getCurrentStandardErrContents()
      Returns everything that has been received on the spawn's stderr during this session.
      java.lang.String getCurrentStandardOutContents()
      Returns everything that has been received on the spawn's stdout during this session.
      int getExitValue()
      Retrieve the exit code of a finished process.
      void interact()
      Allows the user to interact with the spawned process.
      boolean isClosed()
      This method can be use use to check the target process status before invoking send(String)
      java.lang.String matched()
      Returns the current matched string
      void send​(java.lang.String string)
      Writes a string to the standard input of the spawned process.
      void stop()
      This method kills the process represented by SpawnedProcess object.
      • Methods inherited from class java.lang.Object

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

      • expect

        public void expect​(java.lang.String pattern)
                    throws java.io.IOException,
                           TimeoutException
        Except pattern string on std out
        Parameters:
        pattern - Regular expression pattern which you excpet
        Throws:
        java.io.IOException - If some other I/O error occurs
        TimeoutException - If timeout in m_lDefaultTimeOutSeconds
      • expect

        public void expect​(java.lang.String pattern,
                           int bufferSize)
                    throws java.io.IOException,
                           TimeoutException
        Except pattern string on std out
        Parameters:
        pattern - Regular expression pattern which you excpet
        bufferSize - The buffer size
        Throws:
        java.io.IOException - If some other I/O error occurs
        TimeoutException - If timeout in m_lDefaultTimeOutSeconds
      • expect

        public void expect​(java.lang.String pattern,
                           long timeOutSeconds)
                    throws java.io.IOException,
                           TimeoutException
        Except pattern string on std out
        Parameters:
        pattern - Regular expression pattern which you excpet
        timeOutSeconds - The timeout seconds
        Throws:
        java.io.IOException - If some other I/O error occurs
        TimeoutException - If timeout in m_lDefaultTimeOutSeconds
      • expect

        public void expect​(java.lang.String pattern,
                           long timeOutSeconds,
                           int bufferSize)
                    throws java.io.IOException,
                           TimeoutException
        Except pattern string on std out
        Parameters:
        pattern - Regular expression pattern which you excpet
        timeOutSeconds - The timeout seconds
        bufferSize - The buffer size
        Throws:
        java.io.IOException - If some other I/O error occurs
        TimeoutException - If timeout in m_lDefaultTimeOutSeconds
      • expect

        public int expect​(java.lang.String[] patterns)
                   throws java.io.IOException,
                          TimeoutException
        Except pattern string on std out
        Parameters:
        patterns - Regular expression pattern array which you excpet
        Returns:
        -1: failed, others: the patterns index which is match
        Throws:
        java.io.IOException - If some other I/O error occurs
        TimeoutException - If timeout in m_lDefaultTimeOutSeconds
      • expect

        public int expect​(java.lang.String[] patterns,
                          long timeOutSeconds)
                   throws java.io.IOException,
                          TimeoutException
        Except pattern string on std out
        Parameters:
        patterns - Regular expression pattern array which you excpet
        timeOutSeconds - The timeout seconds
        Returns:
        -1: failed, others: the patterns index which is match
        Throws:
        java.io.IOException - If some other I/O error occurs
        TimeoutException - If timeout in m_lDefaultTimeOutSeconds
      • isClosed

        public boolean isClosed()
        This method can be use use to check the target process status before invoking send(String)
        Returns:
        true if the process has already exited.
      • getExitValue

        public int getExitValue()
                         throws ExpectJException
        Retrieve the exit code of a finished process.
        Returns:
        the exit code of the process if the process has already exited.
        Throws:
        ExpectJException - if the spawn is still running.
      • send

        public void send​(java.lang.String string)
                  throws java.io.IOException
        Writes a string to the standard input of the spawned process.
        Parameters:
        string - The string to send. Don't forget to terminate it with \n if you want it linefed.
        Throws:
        java.io.IOException - on IO trouble talking to spawn
      • interact

        public void interact()
        Allows the user to interact with the spawned process.
      • stop

        public void stop()
        This method kills the process represented by SpawnedProcess object.
      • getCurrentStandardOutContents

        public java.lang.String getCurrentStandardOutContents()
        Returns everything that has been received on the spawn's stdout during this session.
        Returns:
        the available contents of Standard Out
      • getCurrentStandardErrContents

        public java.lang.String getCurrentStandardErrContents()
        Returns everything that has been received on the spawn's stderr during this session.
        Returns:
        the available contents of Standard Err
      • before

        public java.lang.String before()
        Returns everything that has been received from the last matched expect to the current matched expect
      • matched

        public java.lang.String matched()
        Returns the current matched string