Nach einigen hundert Aufrufen mit Runtime.exec() bekomme ich folgende Exception:
java.IO.Exception: Too many open files
Ich weis dass der Fehler an den Stream-handels liegt, bzw. dass nicht alle geschlossen
werden, nur weis ich nicht welche Handels noch offen sind (siehe Klasse unten).
Kann mir jemand helfen.
Gruss und Merci
Micha Haeusermann
java.IO.Exception: Too many open files
Ich weis dass der Fehler an den Stream-handels liegt, bzw. dass nicht alle geschlossen
werden, nur weis ich nicht welche Handels noch offen sind (siehe Klasse unten).
Kann mir jemand helfen.
Gruss und Merci
Micha Haeusermann
Code:
import java.io.*;
public class Execute {
// Init
static int exitcode = 0;
static String errorout = "";
static String runout = "";
static boolean error = false;
public static boolean runCommand(String command) {
//Log.write("class Execute: call shell command: " + command);
try {
// create Runtimeobject rt
Runtime rt = Runtime.getRuntime();
// create Processobject pr
Process pr = rt.exec(command);
// wait until process is done
pr.waitFor();
// check for errors
exitcode = pr.exitValue();
// create process error reader
BufferedReader perror = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
// create process output reader
BufferedReader poutput = new BufferedReader(new InputStreamReader(pr.getInputStream()));
// write error to log
if (exitcode != 0) {
//Log.write("Error: class Execute: exit code: " + exitcode);
while ((errorout = perror.readLine()) != null) {
//Log.write("Error: class Execute: " + errorout);
}
error = true;
}
else {
//Log.write("class Execute: Done, exit code: " + exitcode);
}
// write output to runout (only first line)
runout = poutput.readLine();
if (runout == null) {
runout = "";
}
// destroy not longer used instances
pr.getErrorStream().close();
pr.getInputStream().close();
pr.getOutputStream().close();
poutput.close();
perror.close();
pr.destroy();
}
// catch exceptions and write it to log
catch (Exception e) {
error = true;
//Log.write("Error: class Execute: exception: " + e.toString());
}
// return true if an error occurred
return error;
}
}