Capturing System.out messages

Hey all,
Just wondering what the easiest way to capture System.out messages of a process, and store these messages in an Array, Vector, or a Buffer where I could read these messages line by line later?
Basically one process System.out.println()'s information I need to use as a variable for a second process. Any help would be greatly appreciated.
Thanks!

Here is a class which redirects standard out and err to a JscrollPane.
import java.io.*;
import javax.swing.*;
public class EOutputConsole extends JScrollPane {
  Object lock = new Object();
  final JTextArea text = new JTextArea(10,30);
  PrintStream consoleOut;
  public EOutputConsole() {
    setViewportView(text);
    setupOutput();
   * An extention of PrintStream that notifies a lock
   * as it's executing its write method. This tells
   * an output console that it has input ready.
  class ConsolePrintStream extends PrintStream {
    Object lock;
    public ConsolePrintStream(Object lock, OutputStream out) {
      super(out);
      this.lock = lock;
    public void write(byte[] buf,
                      int off,
                      int len) {
      synchronized(lock) {
        lock.notify();
        super.write(buf,off,len);
   * A class that extends PrintStream to throw away all
   * input sent to it. This is used to supress standard out
   * and speed up test model runs with debugging output
  class NullPrintStream extends PrintStream {
    public NullPrintStream(OutputStream out) {
      super(out);
    public void write(byte[] buf,
                      int off,
                      int len) {
  public void suppressStandardOut() {
    // create a dumby temp file to use as an output stream
    // nothing will ever actually be written to the file
    try {
      File dumbFile = File.createTempFile("notme", "not1337");
      dumbFile.deleteOnExit();
      PrintStream out = new NullPrintStream(new FileOutputStream(dumbFile));
      System.setOut( out );
      System.setErr( out );
    } catch(IOException ioe) {
      System.out.println("Error supressing standard out");
      ioe.printStackTrace();
  public void availableStandardOut() {
    System.setOut( consoleOut );
    System.setErr( consoleOut );
  private void setupOutput() {
    Thread printer = new Thread( new Runnable() {
        public void run() {
          PipedInputStream pipe = new PipedInputStream();
          BufferedReader in = new BufferedReader
            (new InputStreamReader( pipe ));
          try {
            PipedOutputStream pipeOut = new PipedOutputStream(pipe);
            consoleOut = new ConsolePrintStream(lock, pipeOut);
            System.setOut( consoleOut );
            System.setErr( consoleOut );
          catch (Exception e) {
            System.out.println("Failed to create Pipe for System.out");
            e.printStackTrace();
            return;
          try {
            for(;;) {
              while(!in.ready()) {
                synchronized(lock) {
                  lock.wait();
              text.append(in.readLine()+"\n");
              verticalScrollBar.setValue(verticalScrollBar.getMaximum());
          } catch (Exception e) {
            System.out.println(e);
            e.printStackTrace();
    printer.setDaemon(true);
    printer.start();
}

Similar Messages

  • How to capture System.out, done by another program

    Hi All,
    My application runs other application in back. How can I capture system.out.println() written by another application & display via dialog box.
    Like :execl() or execv() function in C runtime library. Where every printf() message printed to passed buffer.
    Thank you,
    Avin Patel

    You can create an InputStream from a started process. Then read all the bytes from the inputstream and write them to an outputstream (like System.out)
    Process p = Runtime.getRuntime().exec(COMMAND);
    InputStream is = p.getErrorStream();   //Or another stream
    int[] buffer = new int[128];
    while((read = is.read(buffer)) != -1){
    System.write.out(buffer, 0, read);
    }

  • Java System.out Message on Solaris

    Hi !
    Could somebody tell me, how I can forward all System.out Messages from
    my Java modules (EJB, Servlets) to the Solaris Terminal window?
    Thanks Eddie

    You could do a tail -f on the kjs console log. (Assuming that you only have one KJS).

  • How to make add the program system.out messages to a applet text field?

    How to make add the program system.out messages to a applet text field?
    System.out.println("I wanna displany this message on a applet text field, thanks");

    You may wish to change the output destination to a JTextArea. Please have a look at this link that likely shows what you want:
    [http://forums.sun.com/thread.jspa?forumID=54&threadID=640376|http://forums.sun.com/thread.jspa?forumID=54&threadID=640376]
    If you need other examples, search the forum. I found the search terms -- redirect system out textarea -- very helpful.
    Good luck

  • Invoking Java from C and capturing System.out

    Hi,
    I know very little about C but have a question related to invoking a Java process from C. Perhaps someone can help me.
    I've been looking at the example at http://java.sun.com/docs/books/jni/html/invoke.html and seen how to invoke my Java program with:
    (*env)->CallStaticVoidMethod(env, cls, mid, args);
    in their example the Java program prints one line to System out with:
    System.out.println("Hello World " + args[0]);
    and says running the program produces:
    Hello World from C!
    What I want to know is, how in the C program can I capture the output the Java program sends to System.out, as I want to do something with the output other than have it print into the console.
    Hope that makes sense.

    I'm not totally clear on your question but I'll take a stab.
    It seems to me like you are trying to get the output from a java program into a C program. If this is the case then there are many ways to do this - many of which are more simple that using JNI. However, if you absolutely must use JNI for this application then I suggest you take some more time to learn about C and JNI as I imagine this sort of thing is non-trivial and will required a level of understanding of C that you currently don't have. You may also want to cross-post onto the JNI forum.
    If you can do this without using JNI then I'd suggest doing the standard fork/exec/pipe routine. This means, that in your C program you will call the functions fork (to create a new process that is subordinate to the currently running one), exec (in the subprocess which will replace the current program image in memory with that of another program you wish to execute, in this case, a JVM with a running application), and popen (which creates a "pipe" between the standard output of the Java program [System.out] and some input stream in the C program).
    Finding an example of a program that does this fork/exec/pipe pattern on the web shouldn't be too hard. Hope this helps.
    -mike

  • System.out.println capture to buffer

    Hi All,
    My application runs other application in back. How can I capture system.out.println() written by another application & display via dialog box.
    Like :execl() or execv() function in C runtime library. Where every printf() message printed to passed buffer.
    Thank you,
    Avin Patel

    If i understand your question correctly, you should execute command for you help.html file. The system will run default browser.
    such as:
    void runBrowser(String file)
    {String cmd = null;   
         Process p;   
              try  {       
                   String os = System.getProperty("os.name");            
                   if (os != null && os.startsWith("Windows")) {           
                        if (os.startsWith("Windows 9") || os.startsWith("Windows Me")) 
                        // Windows 9x/Me               
                             cmd = "start " + file;
    else
                        // Windows NT/2000/XP               
                             cmd = "cmd /c start " + file;
    p = Runtime.getRuntime().exec(cmd);            
    catch(IOException x)
    // couldn't exec browser
    System.err.println("Could not invoke browser, command=" + cmd);
    }

  • System.out.println logged to ?

    I am using Oracle 9ias 9.0.3 java edition.
    I have deployed a war file successfully using EM.
    i HAVE System.out.println statements in my servlets. I was unable to find any documents which tell me where these statements will be logged?
    Any one help me.

    Go to server properties page of OEM and edit OC4J options under Command Line Options. You will have to specify the OC4J option -out filename to capture the System.out messages. You can also specify the option -err filename to capture all the errors.
    check out http://technet.oracle.com/tech/java/oc4j/htdocs/oc4j-logging-debugging-technote.html

  • Print System.out.println messages into logs of Weblogic Application Server

    Hi,
    I use Weblogic Application Server 10.3.6 on Windows 7. The Enterprise Application (J2EE) is deployed into the 'AdminServer' of Weblogic. For debugging purpose, I have added a few System.out.println statements.
    I am unable to see the print messages on any of log files available in path 'user_projects > domains > base_domain > servers > AdminServer > logs'. However, I can see them on the 'command' prompt which was used to start the server. How can I get them into one of the log files? What am I missing?
    I tried reading other threads on the forum and as per them 'System.out.println' gets logged onto *.out logs which I am unable to find. Only base_domain.log, AdminServer.log, access.log are available in the location.
    More Specifics:
    Configuration on WLS console 'Home > Servers > AdminServer > Logging'
    Log file name: logs/AdminServer.log
    Min. Severity to log: Notice (tried with Debug as well)
    Advanced Options:
    Logging Implementation: JDK
    Redirect stdout logging enabled: False (tried both options)
    Log file Severity Level: Notice (tried with Debug as well)
    Standard Out Severity Level: Notice (tried with Debug as well)
    Thanks

    Paul,
    I just found this on google:
    'Generally, developers put a lot of System.out.println statements in their code to perform application debugging. Normally, all standard outputs and error outputs are routed to the console where the OC4J server is started. If you want to capture the standard output and error outputs to files for logging/debugging purposes, then you can use the -out and -err options while starting up the Oc4J server to specify which files to use.'.
    http://www.onjava.com/pub/a/onjava/2002/01/16/oracle.html?page=2

  • How to capture System.err and System.out in a method?

    Is there some way to capture everything that is sent to System.err or System.out and have it instead go to e.g. a method as a String?
    The reason I want to do is this: I am invoking some method from a class that sends output to System.err and System.out but while that method is run, I want everything that goes to System.out or System.err to instead go to a String buffer or a Swing Scroll Pane.
    What is the easiest way to do this?

    I want everything that goes to System.out or System.err to instead go to a String buffer or a Swing Scroll Pane.Then maybe you should be searching (and then posting) in the Swing forum. Thats where I've seen this question asked and answered many times in the past.

  • BPC 5.0.502  BPC Web Error Message: Exxception of Type System out of memory

    In the process of updating a web page in the content library, page crashed received an error message of "Exception of type System out of memory.  Exception was throw".  What does this mean?  We are now unable to open this sheet without receiving the prior message.  Any remadies would be appreciated.

    Hello,
        Did you receive this specific error message only managing that web page or for all pages?
        Did you try to stop all COM+ components on the application servers(on each if you are using more). It looks to be related to some memory problems.
        If the problem is related to a specific web page, the problem can be related to the content of that web page.
    Best regards,
    Mihaela

  • Tomcat Java Servlets, how to log System.out.println() messages

    I have recently installed a new (x86) Mac OS Xserve, and am porting some Java application Servlets from an existing older Mac OSX server. All the servlets were working (I am connecting via port 9006). I have carefully used the old JDK 1.4 compiler, edited my server.xml (for port 9006) and web.xml files, etc. The Tomcat example servlets work fine, and all my (other) servlets work fine, with one exception, where I get the typically vague "java.io.IOException: Server returned HTTP response code: 500" message.
    Trouble is, I cannot get the Java System.out.prinln statements to go to the Tomcat/logs/ log files (they are all there and updating with Tomcat HttpServlet messages), in order to properly debug.
    Is there a server.xml value somewhere I can make the change?
    On another minor (possibly related) point, does anyone know what the path info ='null' means in the Tomcat access log? e.g.,
    StandardContext[/my_servlets]: Mapped to servlet 'myServlet' with servlet path '/myServlet' and path info 'null'
    It is the only other suspicious message I get in all the logs.
    One other point: my java application that fails uses threads. All the individual classes that use the threads work when run interactively, but as soon as I call them from final Serlet class that extends HttpServlet, I get a null pointer exception. Is there something unique about the Tomcat 4.1 threading that could be causing it?
    I want to avoid upgrading to Tomcat 5 at this point, if I can avoid it. My applications are modest in scope, and the last time I upgraded to Tomcat 5, it took me days to get it working properly, and I lost all access to it from the Server Admin application.

    I have found a solution: Via the Tomcat Admin web page I set the Context field "Swallow Output" to "true".

  • How to view System.out.print() messages for adapters in OIM 9.0.3

    I have created an adaptor for OIM from a java jar file. When that adaptor executes after some updates on tables it produces some execptions/error.
    I can not see the details of these exceptions as I do not know where is the standard output located when adapter is executed via OIM.
    Where cen I see output from my code lines that contain: System.out.println()?
    thanks

    I am not sure if logging is enabled as OIM was installed previously by another person - how can I check if it is enabled and how to use log4j in this case?
    OIM Design Console window shows no messages comming from my System.out.print() statements.
    /br
    Djeno

  • How to open the server log file that displays messages of System.out.print

    Hi,
    I am working on a j2ee project. How can we access the default log file? I have put many System.out.println(..) method in different classes in order to get the program flow and to track the origin of the error.
    I opened the a log file named "defaultTrace.0.trc" in usr\sap\J2E\JC00\j2ee\cluster\server0\log installation directory. Although it shows the ecxeptions, It is not showing the messages that i have written to console with the help of System.out.println(..) method.
    Can anybody tell me the location of the log file where i can find my messages sent through System.out.println(..) function?
    Regards,
    Sudheesh...

    System.out.println goes to console, which is not a file... This whole thing is much easier if you use standard logging:
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/5c830ca67fd842b2e87b0c341c64cd/frameset.htm

  • I want to capture system message during data upload.

    Hello,
    I want to capture system message during data upload.
    How should I do this?
    suppose during call transaction system shows message:-
    " Info record for vendor 102925 and material DYND80000 does not exist"
    then How can I get that message?

    Hi Megha,
    CALL TRANSACTION tcode USING i_bdcdata
                              MODE lws_mode
                            UPDATE lws_update
                          MESSAGES INTO <b>i_messages.</b>
      CLEAR wa_error.
      IF sy-subrc NE 0.
        cnt_failed = cnt_failed + 1.
        wa_error-status = c_fail.
        LOOP AT i_messages . "WHERE msgtyp EQ 'E' OR msgtyp = 'A'.
          flg_fail = c_x.
    *---Calling FM to get for Error Message Text
          <b>CALL FUNCTION 'MESSAGE_PREPARE'  </b>                     "#EC *
            EXPORTING
              language               = 'E'
              msg_id                 = i_messages-msgid
              msg_no                 = i_messages-msgnr
            IMPORTING
              msg_text               = lws_text
            EXCEPTIONS
            function_not_completed = 1      " Invalid Date Error Description
              message_not_found      = 2
              OTHERS                 = 3.
    <b>Reward points if this helps.
    Manish</b>

  • Where to see the System.out.println() messages

    I deploy my application in Oracle9ias . I have some System.out.println() statements in java class files.
    When I run the application I need to know where I can see those println() statements.

    The Member Feedback forum is for suggestions and feedback for OTN Developer Services. This forum is not monitored by Oracle support or product teams and so Oracle product and technology related questions will not be answered. We recommend that you post this thread to the Application Server-General forum. The URL is:
    Oracle Application Server - General

Maybe you are looking for