Package gw.util
Class ShellProcess
- java.lang.Object
-
- gw.util.ShellProcess
-
public class ShellProcess extends Object
-
-
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 notString
readChar()
String
readLine()
Reads a line of text from stdout.String
readStderrLine()
Reads a line of text from stderr.String
readStderrUntil(char character, boolean includeDeliminator)
Reads a group of text from stderr.String
readUntil(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 thisProcess
object has terminated.void
write(String text)
Writes the specified text to stdin
-
-
-
Method Detail
-
readLine
public 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 String readUntil(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 untilincludeDeliminator
- true to include the deliminator in the returned text, false to not.- Returns:
- The text that was read
-
readChar
public String readChar()
-
readStderrLine
public 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 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 untilincludeDeliminator
- true to include the deliminator in the returned text, false to not.- Returns:
- The text that was read
-
write
public void write(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 InterruptedException
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.
-
-