try {
//String args = StringUtils.toStringList(Arrays.asList(params), false);
Process proc = Runtime.getRuntime().exec(params);
BufferInputStream sin = new BufferInputStream(getStdIn());
sin.setTimeout(1000);
OutputStream nout = new BufferedOutputStream(proc.getOutputStream());
final OutputStream sout = new BufferOutputStream(getStdOut());
final InputStream nis = new BufferedInputStream(proc.getInputStream(), 80);
// now copy from in to out and copy from out to in. This is not very nice
// we need two threads
Thread treader = new Thread() {
public void run() {
try {
IOUtils.copy(nis, sout, 80);
//log.debug("chk11");
exitVal[0] = 0;
} catch (Exception ex) {
exitVal[0] = 1;
}
}
};
//log.debug("chk3");
treader.start();
//log.debug("chk4");
sin.setAsyncMode(true);
byte[] buf = new byte[80];
int bc = sin.read(buf);
while (bc != -1 && exitVal[0] == -1) {
nout.write(buf, 0, bc);
bc = sin.read(buf);
}
//log.debug("chk5");
proc.waitFor();
//log.debug("chk6");