public class ProcessStreamDrainer extends Object
Sample Code:
ProcessBuilder pb = new ProcessBuilder("ls", "-R", "c:/as"); try { Process p = pb.start(); ProcessStreamDrainer psd = ProcessStreamDrainer.drain("MyProcess", p); // or ProcessStreamDrainer psd = ProcessStreamDrainer.redirect("MyProcess", p); psd.waitFor(); // this is optional. } catch (Exception ex) { ex.printStackTrace(); }
Modifier and Type | Method and Description |
---|---|
static ProcessStreamDrainer |
dispose(String processName,
Process process)
Create an instance, drain and throw away the process' stderr and stdout output.
|
static ProcessStreamDrainer |
drain(String processName,
Process process)
Create an instance and drain the process' stderr and stdout
|
String |
getErrString() |
String |
getOutErrString() |
String |
getOutString() |
static ProcessStreamDrainer |
redirect(String processName,
Process process)
Create an instance, drain and redirect the process' stderr and stdout to
System.err and System.out respectively.
|
static ProcessStreamDrainer |
save(String processName,
Process process)
Create an instance and drain the process' stderr and stdout and save it to
strings.
|
void |
waitFor()
Wait for the drain threads to die.
|
public static ProcessStreamDrainer drain(String processName, Process process)
process
- The Process to drainprocessName
- The name will be used to name the drainer threadspublic static ProcessStreamDrainer save(String processName, Process process)
process
- The Process to drainprocessName
- The name will be used to name the drainer threadspublic static ProcessStreamDrainer redirect(String processName, Process process)
process
- The Process to drainprocessName
- The name will be used to name the drainer threadspublic static ProcessStreamDrainer dispose(String processName, Process process)
process
- The Process to drainprocessName
- The name will be used to name the drainer threadspublic final void waitFor() throws InterruptedException
InterruptedException
public final String getOutString()
public final String getErrString()
public final String getOutErrString()
Copyright © 2021. All rights reserved.