Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Avviare eseguibile con java su macchina sun

    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;
            }
        }
    }

  2. #2
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,326

    Moderazione

    Quando si posta del codice, è necessario usare gli sppositi tag CODE (vedi http://forum.html.it/forum/showthread.php?s=&threadid=973889]Regolamento interno[/url], punto 6).

    Li ho aggiunti io alla tua discussione.

    Devi, inoltre, specificare se ottieni degli errori... magari la JVM ti dà qualche messaggio in esecuzione? Quali?


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.