Class Spawn
- java.lang.Object
-
- com.santaba.agent.groovyapi.expect.expectj.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 expectvoid
expect(java.lang.String pattern)
Except pattern string on std outint
expect(java.lang.String[] patterns)
Except pattern string on std outint
expect(java.lang.String[] patterns, long timeOutSeconds)
Except pattern string on std outvoid
expect(java.lang.String pattern, int bufferSize)
Except pattern string on std outvoid
expect(java.lang.String pattern, long timeOutSeconds)
Except pattern string on std outvoid
expect(java.lang.String pattern, long timeOutSeconds, int bufferSize)
Except pattern string on std outvoid
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 invokingsend(String)
java.lang.String
matched()
Returns the current matched stringvoid
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.
-
-
-
Method Detail
-
expectClose
public void expectClose(ExpectedOutputHandler stdOutHandler, ExpectedOutputHandler stdErrHandler, long lTimeOutSeconds) throws java.io.IOException, TimeoutException, ExpectJException
Wait for the spawned process to finish.- Parameters:
stdOutHandler
- - the handler to properly consume output from stdoutstdErrHandler
- - the handler to properly consume output from stderrlTimeOutSeconds
- The number of seconds to wait before giving up, or -1 to wait forever.- Throws:
ExpectJException
- if we're interrupted while waiting for the spawn to finish.TimeoutException
- if the spawn didn't finish inside of the timeout.java.io.IOException
- See Also:
expectClose(ExpectedOutputHandler, ExpectedOutputHandler)
-
expectClose
public void expectClose(long timeOutSeconds) throws TimeoutException, ExpectJException
- Parameters:
timeOutSeconds
- The timeout seconds of close- Throws:
TimeoutException
- If not close in timeOutSecondsExpectJException
- If wait close has interrupt
-
expectClose
public void expectClose(ExpectedOutputHandler stdOutHandler, ExpectedOutputHandler stdErrHandler) throws java.io.IOException, ExpectJException, TimeoutException
Wait the default timeout for the spawned process to finish.- Parameters:
stdOutHandler
- - handler for possible stdout outputstdErrHandler
- - handler for possible stderr output- Throws:
ExpectJException
- If something fails.TimeoutException
- if the spawn didn't finish inside of the default timeout.java.io.IOException
- See Also:
expectClose(ExpectedOutputHandler, ExpectedOutputHandler, long)
,ExpectJ(long)
-
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 occursTimeoutException
- 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 excpetbufferSize
- The buffer size- Throws:
java.io.IOException
- If some other I/O error occursTimeoutException
- 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 excpettimeOutSeconds
- The timeout seconds- Throws:
java.io.IOException
- If some other I/O error occursTimeoutException
- 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 excpettimeOutSeconds
- The timeout secondsbufferSize
- The buffer size- Throws:
java.io.IOException
- If some other I/O error occursTimeoutException
- 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 occursTimeoutException
- 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 excpettimeOutSeconds
- The timeout seconds- Returns:
- -1: failed, others: the patterns index which is match
- Throws:
java.io.IOException
- If some other I/O error occursTimeoutException
- If timeout in m_lDefaultTimeOutSeconds
-
isClosed
public boolean isClosed()
This method can be use use to check the target process status before invokingsend(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
-
-