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.

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

  • 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();
    }

  • How to capture show layer and hide layer event in photoshop through a plugin???

    How to capture show layer and hide layer event in photoshop through a plugin???for mac

    Use the Listener plug-in found in the SDK to see how you can monitor the show/hide layer event. You can also use the Getter plug-in to show what information you can find out about the current state of Photoshop.

  • How to capture the date and time of  a background job

    Hi experts,
    How to capture the date and time of  a background job?
    How to find whether it is runned succesfully or not?
    If it is not successful how to put error message?
    ASAP
    Thanx in advance,
    Sudha

    To Display the STATUS of the JOB which is exectued in background
      CLEAR : wa_jobsteplist.
      REFRESH : i_jobsteplist.
      WRITE:/ 'DISPLAYING JOB STATUS'.
      CALL FUNCTION 'BP_JOB_READ'
        EXPORTING
          job_read_jobcount           = w_jobcount
          job_read_jobname            = w_jobname
          job_read_opcode             = '20'
        JOB_STEP_NUMBER             =
       IMPORTING
         job_read_jobhead            = wa_jobhead
       TABLES
         job_read_steplist           = i_jobsteplist
    CHANGING
       RET                         =
       EXCEPTIONS
         invalid_opcode              = 1
         job_doesnt_exist            = 2
         job_doesnt_have_steps       = 3
         OTHERS                      = 4
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    To Display the status text as per the status type
      CASE wa_jobhead-status.
        WHEN 'S'. WRITE: / 'Scheduled'.
        WHEN 'R'. WRITE: / 'Released'.
        WHEN 'F'. WRITE: / 'Completed'.
        WHEN 'A'. WRITE: / 'Cancelled'.
        WHEN OTHERS.
      ENDCASE.

  • 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

  • How to capture System Error in XI?

    Hello All,
    1. Can any one tell me , How to capture the system error , Adapter Error and send the alert to make sure the guarenteed delivery from Source to Target via XI ?
    2.I have done the configuration for to capture the mapping error in transaction ALRTCATDEF .But still i am not able to see any messages in my Alert Inbox???
    I have checked with the two weblogs Alert step by step and Alert Trouble shooting guide.but still i am not getting any messages in Alert inbox .Any one can tell me how to fix this?
    Thanks!

    Hi,
      You wrote:
    <i>How to capture the system error , Adapter Error </i>
    Errors are captures in many ways and at different stages,
    like alert, sld errors or even sxmb_moni or even with visual administrator trace, I am not sure of your requirement but if you want a centrlished point to access all these error you may refer a good example as,
    /people/michal.krawczyk2/blog/2005/09/07/xi-why-dont-start-searching-for-all-errors-from-one-place
    <i>have checked with the two weblogs Alert step by step and Alert Trouble shooting guide.but still i am not getting any messages in Alert inbox .Any one can tell me how to fix this?</i>
    The two weblogs are my favourite and best resources but still if you are missing, please elaborate if you are getting any errors or other fesible traces as to why your alerts are not coming in inbox.
    Regards,
    Anirban.

  • 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 get System.out msg displayed in logs

    Running SJSWSEE6.1 SP5 on Solaris
    How do I get the System.out.println messages to display in the Web Server 6.1 error/access log??
    Thanks..

    Hi,
    In your server.xml, check that the properties 'logstderr' and 'logstdout' are set to 'true'. The messages will then appear in the errors log file.
    <LOG file="<path to errors file>" loglevel="info" logtoconsole="true"
    usesyslog="false" createconsole="false" logstderr="true" logstdout="true" logvsid="false"/>
    Also, see docs at http://docs.sun.com/source/817-6248/crsrvrx.html
    Hope this helps.

  • How to replace System.out.println() using templates

    can you give the complete code for my problem which is given below.
    package include;
    public class P
    public static cout(int a)
    System.out.println( a);
    public static cout(int a,int b)
    System.out.println(a + b);
    // like this i need to write to accept parameters from the class. which is importing this package
    for some more examples
    public static cout(int a,String s)
    System.out.printn(a +s);
    and many more type i.e. all types of arrangements of datatypes
    the above is the package called "include" Now Iam Importing the package in the class Hello:
    import include.P;
    public class Hello
    public static void main(String args[])
    int i=10;
    float f=12.23;
    String s="hello";
    P.cout(i,f); //cout is the static method of package(include) class " P"
    P.cout("welcome",s)
    // like this I want to send any type and any no of arguments as the System.out.println()
    will handle.
    My aim is to replace the System.out.println() with P.cout() which can be achieve in my idea by calling the static method ( such as cout() ) which internally use System.out.println() method. I am facing problem in achieving this because we donot know which type and how many parameters he will send .
    My task is we have to create a method which will accept any no.of arguments and is of any type.I think this can be done BY USING TEMPLATES.
    So please understand my problem and send me reply.I am waiting for your reply.
    thank you.

    Although I am not sure why you are doing this, if you really are trying to code a replacement for System.out.println then:
    out is a PrintStream and the println methods of PrintStream have the following signatures:
    void println()
    Terminate the current line by writing the line separator string.
    void println(boolean x)
    Print a boolean and then terminate the line.
    void println(char x)
    Print a character and then terminate the line.
    void println(char[] x)
    Print an array of characters and then terminate the line.
    void println(double x)
    Print a double and then terminate the line.
    void println(float x)
    Print a float and then terminate the line.
    void println(int x)
    Print an integer and then terminate the line.
    void println(long x)
    Print a long and then terminate the line.
    void println(Object x)
    Print an Object and then terminate the line.
    void println(String x)
    Print a String and then terminate
    So you should only need to create corresponding methods.

  • Hibernate how to  disable system.outs.....

    Hi
    I am using hibernate to conect to mySQL database, but I am getting a bunch of system.outs that slow down the process.
    is there anyyway tor emove this system outs form there
    I am suing netbeans and javax.persistence
    example:
    [TopLink Config]: 2007.10.16 03:56:38.125--ServerSession(1760304)--Connection(19157736)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    User: root@localhost
    Database: MySQL Version: 5.0.45-community-nt
    Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-3.1.14 ( $Date: 2006-10-18 17:40:15 +0200 (Wed, 18 Oct 2006) $, $Revision: 5888 $ )
    [TopLink Config]: 2007.10.16 03:56:38.125--ServerSession(1760304)--Connection(29310343)--connecting(DatabaseLogin(
    platform=>MySQL4Platform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/eece419_colibri"
    [TopLink Config]: 2007.10.16 03:56:38.125--ServerSession(1760304)--Connection(30472956)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    User: root@localhost
    Database: MySQL Version: 5.0.45-community-nt
    Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-3.1.14 ( $Date: 2006-10-18 17:40:15 +0200 (Wed, 18 Oct 2006) $, $Revision: 5888 $ )
    [TopLink Config]: 2007.10.16 03:56:38.125--ServerSession(1760304)--Connection(17680053)--connecting(DatabaseLogin(
    platform=>MySQL4Platform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/eece419_colibri"
    [TopLink Config]: 2007.10.16 03:56:38.140--ServerSession(1760304)--Connection(12122347)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    User: root@localhost
    Database: MySQL Version: 5.0.45-community-nt
    Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-3.1.14 ( $Date: 2006-10-18 17:40:15 +0200 (Wed, 18 Oct 2006) $, $Revision: 5888 $ )
    [TopLink Config]: 2007.10.16 03:56:38.140--ServerSession(1760304)--Connection(31332340)--connecting(DatabaseLogin(
    platform=>MySQL4Platform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/eece419_colibri"
    [TopLink Config]: 2007.10.16 03:56:38.140--ServerSession(1760304)--Connection(5218268)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    User: root@localhost
    Database: MySQL Version: 5.0.45-community-nt
    Driver: MySQL-AB JDBC Driver Version: mysql-connector-java-3.1.14 ( $Date: 2006-10-18 17:40:15 +0200 (Wed, 18 Oct 2006) $, $Revision: 5888 $ )
    [TopLink Config]: 2007.10.16 03:56:38.140--ServerSession(1760304)--Connection(25699763)--connecting(DatabaseLogin(
    platform=>MySQL4Platform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/eece419_colibri"
    [TopLink Config]: 2007.10.16 03:56:38.156--ServerSession(1760304)--Connection(33539718)--Connected: jdbc:mysql://localhost:3306/eece419_colibri
    thanks !!

    First, read the documentation of Toplink how to configure their logger.
    Second, it look like that you're creating a new session everytime on every query? That is very expensive. Your code logic might need a review.

  • 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".

  • Bex Query - How to capture characteristic value and set it as filter value?

    Dear Experts,
    I would like to create a tricky report that listed sales quantity by companis. Companies consists of production plant as well as trading company.
    Company / Sales Quantity / Sales Quantity 2 (which produced by Company itself)
    A            / 100                  / 50                     (50 was produced by company A)
    B            /  80                   / 0                      (this is a trading company)
    C            / 150                  / 150                   (All are produced by company C)
    First I thought of using variable to capture Company value and then under Sales Quantity 2 I set producing company = this variable. But this only works if I filter company values. Any workaround idea that I can get the above with all the listing of companies?
    Any assistance would be great! Thanks!
    JL

    Hi,
    Have you tried elimination of Internal business Volume?
    http://help.sap.com/saphelp_bw32/helpdata/en/d5/784d3c596f0b26e10000000a11402f/content.htm
    Impliment this solution  by adding another KF Sales qty2.  with ref. to Sales qty.
    In characteristic pair you can have Company and  Production Company(navigational attribute).
    By implimenting this solution  the system will eliminate if the quantity is produced by the company it self.  You can create CKF in query to get the result you need.
    Jaya

  • How to capture the screen and send it to attachment for that mail

    hi sir ,
         how to capture the screen shot and attach with that e-mail , whether it is possible or not ..
    Regards,
    kumar

    hi sir,
        i am asking about while creating the support message from help menu in sap..
    while creating the support message we have to give component , priority and text also .. after that click the send icon in that support desk message .. while clicking the send button the entire screen ( what  we have entered in that creen na ) i have to capture the screen ( it may be save in local file also )  after that it will attach into attachment and then send it to ...
    Regards,
    kumar

  • How to capture user name and date in the database

    How to capture the person name who edits the application and the date of edit in the database...
    Pallavi

    Hi
    There are substitution strings you can use for this purpose.
    1.APP_USER ------is the current user running the application
    2.SYSDATE --------represents the current date on the database server
    APP_USER Syntax
    Bind variable------ :APP_USER
    PL/SQL------- V('APP_USER')
    Substitution string---------- &APP_USER.
    SYSDATE_YYYYMMDD Syntax
    Bind variable------- :SYSDATE_YYYYMMDD
    Direct PL/SQL------- APEX_APPLICATION.G_SYSDATE (DATE DATATYPE)
    PL/SQL-------- V('SYSDATE_YYYYMMDD')
    Your application will be based on a table with primary key column. You create a 'before update trigger' on that table and add columns 'UPDATED_ON' and 'UPDATED_BY' to that table. Add the following to that trigger:
    :NEW.UPDATED_ON := SYSDATE;
    SELECT V('APP_USER') INTO :NEW.UPDATED_BY FROM DUAL;
    -Priyanka

Maybe you are looking for