*/
public static class Pipe implements Runnable {
private final InputStream in;
- private final OutputStream out;
+ private final OutputStream out;
private final long sleep;
+ private ByteArrayOutputStream snoop;
private long totalWritten;
private Throwable thrown;
private boolean halt;
this.closeOutput = closeOutput;
this.sleep = Math.min(0l, Math.max(60l*1000l, sleep));
}
-
+
+ public void setSnoop(ByteArrayOutputStream snoop) {
+ this.snoop = snoop;
+ }
+
/**
* Run the pipe.
* This halts on the first Throwable thrown or when a read returns
final int MAX = 4096;
byte[] buf = new byte[MAX];
int count = in.read(buf, 0, MAX);
+ ByteArrayOutputStream mySnoop;
while ((halt && finishStream && (0 < count))
|| (!halt && (-1 != count))) {
out.write(buf, 0, count);
+ mySnoop = snoop;
+ if (null != mySnoop) {
+ mySnoop.write(buf, 0, count);
+ }
totalWritten += count;
if (halt && !finishStream) {
break;
package org.aspectj.util;
+import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
* ...
*/
private String[] command;
+ private String[] envp;
private String label;
private boolean init;
private FileUtil.Pipe errStream;
private FileUtil.Pipe outStream;
private FileUtil.Pipe inStream;
+ private ByteArrayOutputStream errSnoop;
private int result;
private Thrown thrown;
}
public final void init(String[] command, String label) {
- LangUtil.throwIaxIfNotAssignable(command, String.class, "command");
- if (1 > command.length) {
+ this.command = (String[]) LangUtil.safeCopy(command, new String[0]);
+ if (1 > this.command.length) {
throw new IllegalArgumentException("empty command");
}
- this.command = new String[command.length];
- System.arraycopy(command, 0, this.command, 0, command.length);
this.label = LangUtil.isEmpty(label) ? command[0] : label;
this.init = true;
reinit();
}
+ public final void setEnvp(String[] envp) {
+ this.envp = (String[]) LangUtil.safeCopy(envp, new String[0]);
+ if (1 > this.envp.length) {
+ throw new IllegalArgumentException("empty envp");
+ }
+ }
+
+ public final void setErrSnoop(ByteArrayOutputStream snoop) {
+ errSnoop = snoop;
+ if (null != errStream) {
+ errStream.setSnoop(errSnoop);
+ }
+ }
+
/**
* Start running the process and pipes asynchronously.
* @return Thread started or null if unable to start thread
return null;
}
errStream = new FileUtil.Pipe(process.getErrorStream(), System.err);
+ if (null != errSnoop) {
+ errStream.setSnoop(errSnoop);
+ }
outStream = new FileUtil.Pipe(process.getInputStream(), System.out);
inStream = new FileUtil.Pipe(System.in, process.getOutputStream());
// start 4 threads, process & pipes for in, err, out
process.destroy();
}
if (null != inStream) {
- inStream.halt(true,true);
+ inStream.halt(false, true); // this will block if waiting
inStream = null;
}
if (null != outStream) {