# Class: com.pnfsoftware.jeb.util.concurrent.ProcessWrapper

A wrapper around [Process](Process) to execute potentially long\-running commands, that may require input. The process streams are accessible; it is the responsibility of the client to read \(or drain\) the output and error streams to avoid the chance of blocking on [#waitForCompletion()](#waitForCompletion()). This class is an auto\-closable and may be treated as such \(try\-with\-ARM\). 

 A higher\-level, safer alternative to consider if you do not need to handle the process streams is to use [ProcessExec](ProcessExec).

## Constructor: ProcessWrapper
- parameter: `cmdarray`, type: `java.lang.String[]`

Description: Execute a process without timeout. The caller is advised to take care of the target process output and error streams.
parameter: cmdarray: command

## Constructor: ProcessWrapper
- parameter: `timeoutMs`, type: `long`
- parameter: `redirectErrToOut`, type: `boolean`
- parameter: `cmdarray`, type: `java.lang.String[]`

Description: Execute a process with timeout.
parameter: timeoutMs: timeout in milliseconds before the process gets killed \(`<= 0` means no            timeout\)
parameter: redirectErrToOut: true to redirect the process error stream to the output stream
parameter: cmdarray: command

## Method: close

Description: Redirects to [#kill()](#kill()).

## Method: getProcessError
- return type: `java.io.InputStream`

Description: Get the process standard error stream.
return: the process error stream, or null if the process has not been started

## Method: getProcessInput
- return type: `java.io.OutputStream`

Description: Get the process standard input stream.
return: the process input stream, or null if the process has not been started

## Method: getProcessOutput
- return type: `java.io.InputStream`

Description: Get the process standard output stream.
return: the process output stream, or null if the process has not been started

## Method: getReturnCode
- return type: `java.lang.Integer`

Description: Get the process return code.
return: the process return code, or null if no return code has been recorded

## Method: isAlive
- return type: `boolean`

Description: Determine whether the wrapped process is running.
return: true if the process was started and is still alive

## Method: kill

Description: Terminate the process if it is still running and record its return code when available.

## Method: start
- return type: `com.pnfsoftware.jeb.util.concurrent.ProcessWrapper`

Description: Start the process.
return: this wrapper
throws: if the process cannot be started

## Method: toString
- return type: `java.lang.String`


## Method: waitForCompletion

Description: Wait for the process to complete, then update the return code. Calling this method without having reader threads draining the target process's output and error is dangerous unless a timeout was set: if the process generates a lot of output, it will stall indefinitely and block the current thread.

