p = Runtime.getRuntime().exec(“your command”);
StreamGobbler errorGobbler = new
StreamGobbler(p.getErrorStream(), “ERROR”);
StreamGobbler outputGobbler = new
StreamGobbler(p.getInputStream(), “OUTPUT”);
errorGobbler.start();
outputGobbler.start();
int exitCode = p.waitFor();
if(exitCode==0){
result = true;
} else {
String out = “”;
out = errorGobbler.line+ outputGobbler.line ;
log.error(out);
throw new Exception(“Errore durante l’esecuzione di generateIPDV()”);
}
…..
…..
……..
public class StreamGobbler extends Thread {
InputStream is;
String type;
String line ;
StreamGobbler(InputStream is, String type)
{
this.is = is;
this.type = type;
}
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
line += line ;
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}