Capture the output of JAVACTag(s): Environment

method 1a : 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 1a : redirect to stdout with a pause after each screen full

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

method 2 : 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() + ")" );
    }
}

or you can always use a small text editor like Textpad where you can write with Java code (with syntax coloring), compile, capture compiler output and launch your Applet or Application directly from the editor.




If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2012
[ home ]