Ho creato una classe java che deve girare su macchina sun, come faccio ad avviare un eseguibile? esiste una classe predefinita?
questa classe non mi funziona sulla macchina sun (nemmeno se passo i percorsi completi dei parametri), mentre in windows funziona benissimo
codice:import java.io.*; public class RunFile{ private String errorStream = ""; private String outputStream = ""; private String errorRAS = ""; // Metodo che esegue il file .exe (o .bat) 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(); // 1 secondo di attesa (i thread potrebbero star ancora leggendo sulle macchine pi√π veloci) Thread.sleep(1000); errorStream = errorGobbler.getTextStream(); outputStream = outputGobbler.getTextStream(); errors = errors + "Process exitValue: " + exitVal; } catch (Throwable t){ exitVal = -1; } return exitVal; } public String getErrorStream(){ return errorStream; } public String getOutputStream(){ return outputStream; } // CLASSE INTERNA PER LETTURA STREAM private class StreamGobbler extends Thread{ InputStream is; String type; String textStream; StreamGobbler(InputStream is, String type){ this.is = is; this.type = type; } public void run(){ try{ boolean firstErr = false; textStream = ""; BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; while((line = br.readLine()) != null){ textStream = textStream + line + "\r\n"; } } catch(Exception e){ } } public String getTextStream(){ return textStream; } } }

Rispondi quotando

