Originariamente inviato da pcg4m3s
mi riferivo a una situazione del genere:
codice:
ProcBuild p=new ProcBuild();
Runtime rt;
rt = Runtime.getRuntime();
proc = rt.exec("mioEseguibile.exe");
OutputStream out=p.getOutputStream();
si appunto...
se vuoi leggere lo stream devi usare input, non output !!
codice:
// FUNZIONE PER ESEGUIRE UN FILE .EXE O .BAT
public int runFile(String pathfile){
int exitVal = 0;
String errors = "";
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + pathfile);
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
errors = errors + "Process exeFileName: " + pathfile + "\r\n";
while ( (line = br.readLine()) != null){
errors = errors + line + "\r\n";
}
exitVal = proc.waitFor();
errors = errors + "Process exitValue: " + exitVal;
} catch (Throwable t){
// SCRITTURA LOG
System.out.println("JAVA ERROR " + t.getMessage());
exitVal = -1;
}
return exitVal;
}