ciao ecco qua.. questa fa proprio al caso tuo..
codice:
public class RunnableHelper {
public int runFile(String pathfile){
int exitVal = 0;
String errors = "";
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(pathfile);
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
errorGobbler.start();
outputGobbler.start();
exitVal = proc.waitFor();
errors = errors + "Process exitValue: " + exitVal;
} catch (Throwable t){
// SCRITTURA LOG
System.out.println("JAVA ERROR " + t.getMessage());
exitVal = -1;
}
return exitVal;
}
// CLASSE INTERNA PER LETTURA STREAM
class StreamGobbler extends Thread
{
InputStream is;
String type;
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)
System.out.println(type + ">" + line);
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
}