Come eseguire un exe in Java

Java Soft! Commenta l'articolo

java_logo_21 Per eseguire un file esterno, che può essere un exe, un bat per windows, o un .app per MacOSX è molto semplice. La classe che utilizzeremo è Runtime che fa parte del package java.io.

Eccone un esempio.

    import java.io.*;
   
    public class Prova {
        public static void main(String[] args) {
            Runtime run = Runtime.getRuntime();
            try {
            
                Process pp=run.exec("c:\\jdk1.3\\bin\\javac");
                BufferedReader in =new BufferedReader(new InputStreamReader(pp.getErrorStream()));
               String line;
               while ((line = in.readLine()) != null) {
                   System.out.println(line);
               }
               int exitVal = pp.waitFor();
               System.out.println("Process exitValue: " + exitVal);
          } catch (Exception e) {
               e.printStackTrace();
               System.out.println(e.getMessage());
          }
      }
   }

Output

Usage: javac  
where possible options include:
 -g            Generate all debugging info
 -g:none          Generate no debugging info
 -g:{lines,vars,source}  Generate only some debugging info
 -O            Optimize; may hinder debugging or enlarge class file

 -nowarn          Generate no warnings
 -verbose         Output messages about what the compiler is doing
 -deprecation       Output source locations where deprecated APIs are us
ed
 -classpath      Specify where to find user class files
 -sourcepath     Specify where to find input source files
 -bootclasspath    Override location of bootstrap class files
 -extdirs       Override location of installed extensions
 -d       Specify where to place generated class files
 -encoding    Specify character encoding used by source files
 -target      Generate class files for specific VM version

Process exitValue: 2

Scrivi un Commento

Home | Graffiti e Disegni | Educazione | Chi siamo | Blog | Progetti | Contatti
RSS Feed Comments RSS Accedi