Friday, 14th October 2011
Follow WikiJava on twitter now. @Wikijava

Capture the output of JAVAC

From WikiJava

Jump to: navigation, search


This tutorial contains three methods to get the output of the compilation of the Javac machine.

Contents

the article

method redirect to a file

// Win95 (?)
   javac -J-Djavac.pipe.output=true myClass.java >output.txt
// WinNT (or better)
   javac  MyClass.java 2>output.txt

method redirect to stdout with a pause after each screen full

// WinNT (or better)
javac MyClass.java 2>&1 | MORE

method use JAVA to capture the output

//  [JDK 1.1]
//  to compile:  java JC mySource.java
//       (use redirection to keep the output)
//               java JC mySource.java >output.txt
 
import java.io.*;
public class JC {
  public static void main( String args[] )
     throws IOException, InterruptedException {
    String fn = "JC.java";
    if( args.length > 0 ) fn = args[0];
    System.out.println( "BEGIN (" + fn + ")" );
    Process p = 
        Runtime.getRuntime().exec( "javac -verbose " + fn );
    String buf;
    BufferedReader se = new BufferedReader
        ( new InputStreamReader( p.getErrorStream() ) );
    while( (buf = se.readLine()) != null ) 
       System.out.println( " : " + buf );
    System.out.println( "END (rc:" + p.waitFor() + ")" );
    }
}

See Also

Real's Java How To

Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page


Comments on wikijava are disabled now, cause excessive spam.