//System.out.println("going to run java class with command -->" + command);
//System.out.println("current working dir for command is -->" + this.pathToClass);
java.lang.Process p = pb.start();
int exitCode = -1;
StreamReader outputStreamReader = new StreamReader(p.getInputStream());
StreamReader errorStreamReader = new StreamReader(p.getErrorStream());
outputStreamReader.start();
errorStreamReader.start();
if(timeOutInMillisec > 0)
{
Timer timer = null;
try
{
timer = new Timer(true);
InterruptTimerTask interrupter = new InterruptTimerTask(Thread.currentThread());
timer.schedule(interrupter, timeOutInMillisec);
exitCode = p.waitFor();
}
catch(InterruptedException e)
{
// do something to handle the timeout here
Log.message("going to kill process with hashcode " + p.hashCode());
p.destroy();
exitCode = JavaClassRunner.kWaitForProcessTimeout;
Log.message("process with hashcode " + p.hashCode() + " killed");
}
finally
{
timer.cancel();
Thread.interrupted();
}
}
else
{
exitCode = p.waitFor();
}
this.outputString = outputStreamReader.toString();
this.errorString = errorStreamReader.toString();
return exitCode;
}