Class AbstractProcessOutput
java.lang.Object
com.github.fracpete.processoutput4j.output.AbstractProcessOutput
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CollectingProcessOutput, ConsoleOutputProcessOutput, StreamingProcessOutput
Ancestor for classes that give access to the output generated by a process.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]the command.protected String[]the environment variables.protected intthe exit code.protected Processthe process.protected AbstractProcessReaderfor monitoring stderr.protected AbstractProcessReaderfor monitoring stdout.protected AbstractProcessRunnablefor monitoring timeouts.protected booleanwhether the process has timed out.protected intthe timeout for the process in seconds (ignored if invalid input: '<' 1).private static final longfor serialization. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AbstractProcessReaderConfigures the reader for stderr.protected abstract AbstractProcessReaderConfigures the reader for stdout.protected AbstractProcessRunnableConfigures the runnable for watching for time outs.voiddestroy()Destroys the process if possible.voidflush()Flushes the readers.String[]Returns the command that was used for the process.String[]Returns the environment.intReturns the exit code.Returns the process.intReturns the timeout for the process in seconds.booleanReturns whether the process has succeeded.booleanReturns whether the process timed out and got terminated.protected voidFor initializing the members.voidmonitor(ProcessBuilder builder) Performs the actual process monitoring.voidPerforms the actual process monitoring.voidmonitor(String input, ProcessBuilder builder) Performs the actual process monitoring.voidPerforms the actual process monitoring.voidPerforms the actual process monitoring.voidsetTimeOut(int value) Sets the timeout for the process in seconds.toString()Returns a short description string.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDfor serialization.- See Also:
-
m_Command
the command. -
m_Environment
the environment variables. -
m_ExitCode
protected int m_ExitCodethe exit code. -
m_Process
the process. -
m_TimeOut
protected int m_TimeOutthe timeout for the process in seconds (ignored if invalid input: '<' 1). -
m_TimedOut
protected boolean m_TimedOutwhether the process has timed out. -
m_ReaderStdErr
for monitoring stderr. -
m_ReaderStdOut
for monitoring stdout. -
m_RunnableTimeout
for monitoring timeouts.
-
-
Constructor Details
-
AbstractProcessOutput
public AbstractProcessOutput()Starts the monitoring process.
-
-
Method Details
-
initialize
protected void initialize()For initializing the members. -
setTimeOut
public void setTimeOut(int value) Sets the timeout for the process in seconds.- Parameters:
value- the timeout (less than 1 for no timeout)
-
getTimeOut
public int getTimeOut()Returns the timeout for the process in seconds.- Returns:
- the timeout (less than 1 for no timeout)
-
monitor
Performs the actual process monitoring.- Parameters:
builder- the process builder to monitor- Throws:
Exception- if writing to stdin fails
-
monitor
Performs the actual process monitoring.- Parameters:
builder- the process builder to monitor- Throws:
Exception- if writing to stdin fails
-
monitor
-
monitor
Performs the actual process monitoring.- Parameters:
cmd- the command that was usedenv- the environmentinput- the input to be written to the process via stdin, ignored if nullprocess- the process to monitor- Throws:
Exception- if writing to stdin fails
-
monitor
Performs the actual process monitoring.- Parameters:
cmd- the command that was usedenv- the environmentinput- the input to be written to the process via stdin, ignored if nullprocess- the process to monitor- Throws:
Exception- if writing to stdin fails
-
configureStdErr
Configures the reader for stderr.- Returns:
- the configured reader
-
configureStdOut
Configures the reader for stdout.- Returns:
- the configured reader
-
configureTimeOutMonitor
Configures the runnable for watching for time outs.- Returns:
- the configured runnable
-
getCommand
Returns the command that was used for the process.- Returns:
- the command
-
getEnvironment
Returns the environment.- Returns:
- the environment, null if process inherited current one
-
hasSucceeded
public boolean hasSucceeded()Returns whether the process has succeeded.- Returns:
- true if succeeded, i.e., exit code = 0 and not timedout
- See Also:
-
getExitCode
public int getExitCode()Returns the exit code.- Returns:
- the exit code
-
hasTimedOut
public boolean hasTimedOut()Returns whether the process timed out and got terminated.- Returns:
- true if timedout
- See Also:
-
getProcess
-
flush
public void flush()Flushes the readers. -
destroy
public void destroy()Destroys the process if possible. -
toString
-