Package gw.util
Class ShellProcess
java.lang.Object
gw.util.ShellProcess
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
void
destroy()
Kills the subprocess.int
Returns the exit value for the subprocess.boolean
Returns true if the process is done, false if notreadChar()
readLine()
Reads a line of text from stdout.Reads a line of text from stderr.readStderrUntil
(char character, boolean includeDeliminator) Reads a group of text from stderr.private String
readStreamUntil
(InputStream stream, boolean includeDelim, char... character) Reads a group of text from stdout.int
waitFor()
Causes the current thread to wait, if necessary, until the process represented by thisProcess
object has terminated.void
Writes the specified text to stdin
-
Field Details
-
_javaProcess
-
_stdin
-
-
Constructor Details
-
ShellProcess
ShellProcess(Process javaProcess)
-
-
Method Details
-
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
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 untilincludeDeliminator
- true to include the deliminator in the returned text, false to not.- Returns:
- The text that was read
-
readChar
-
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
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 untilincludeDeliminator
- true to include the deliminator in the returned text, false to not.- Returns:
- The text that was read
-
write
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
Causes the current thread to wait, if necessary, until the process represented by thisProcess
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:
InterruptedException
- if the current thread isinterrupted
by another thread while it is waiting, then the wait is ended and anInterruptedException
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 value0
indicates normal termination. - Throws:
IllegalThreadStateException
- if the subprocess represented by thisProcess
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 thisProcess
object is forcibly terminated. -
readStreamUntil
-